Solved

USING WC and GREP together

Posted on 1998-11-15
10
2,432 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 54
Error on moodle after upgrade 3 154
while loop over for loop 7 119
"Black Box" Testing of Control System Software 2 122
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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