Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

USING WC and GREP together

Posted on 1998-11-15
10
Medium Priority
?
2,441 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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 100 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

730 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