Solved

USING WC and GREP together

Posted on 1998-11-15
10
2,438 Views
Last Modified: 2013-12-26
I need to use the "GREP" and "WC" commands on a single line to find out how many accounts are in the same group   /etc/passwd (My own server)...what is the proper syntax to use?
0
Comment
Question by:EaglesFan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1294156
grep "^[^:]*:[^:]*:[^:]*:$group:" /etc/passwd | wc
0
 
LVL 2

Expert Comment

by:gothick
ID: 1294157
You can use the "cut" command as an alternative to that grep syntax -- it can cut out
the group column more easily, then you can pass that to grep/wc.
0
 
LVL 5

Expert Comment

by:bchew
ID: 1294158
cut -d: -f3 /etc/passwd | grep <group number> | wc -l
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 5

Expert Comment

by:n0thing
ID: 1294159
awk -F: '{print $4}' /etc/passwd | grep <groupid> | wc -l
is another solution
0
 
LVL 84

Expert Comment

by:ozo
ID: 1294160
#the above solutions with cut and awk probably want to use grep -x
#or, using neither grep nor wc:
perl -F: -ane '$c+=$F[3]=='«groupid»';END{print "$c\n"}' /etc/passwd
0
 
LVL 5

Expert Comment

by:bchew
ID: 1294161
ozo is right about grep -x.  Otherwise, you will be counting groups you didn't intend.  For instance, if you grep for 100 without the -x you would also get groups 1000, 1100, 2100, etc.

0
 
LVL 2

Accepted Solution

by:
kellyjj earned 50 total points
ID: 1294162
grep "<group id>" /etc/passwd |wc -l
0
 
LVL 5

Expert Comment

by:bchew
ID: 1294163
kellyjj

First of all, your "answer" won't work (it will give lots of false hits)!  Furthermore, what you propose is as an has already presented by others as comments!  I believe this is a blatant attempt to "steal" unearned points rather than try to help someone with a solution to their problem.
0
 
LVL 3

Expert Comment

by:braveheart
ID: 1294164
I reckon you should use nawk:

nawk -F: '{groups[$4]++}\\
END      {for (grp in groups) print grp, groups[grp]}' \
/etc/passwd

This will list two columns - the first contains the number of occurences of the group and the second contains the group id.
0
 
LVL 3

Expert Comment

by:braveheart
ID: 1294165
Take it easy.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question