1825694 Members
3262 Online
109686 Solutions
New Discussion

grep per GID

 
SOLVED
Go to solution
tom quach_1
Super Advisor

grep per GID

Hi All,

How can i use grep to return if matching in GID
only and not UID as below.

Thanks in advance.
Tom

cat /etc/passwd |grep 110
(this one will return 3 lines,i want it to return 2 line when matching GID)

oracle:45ILmhXeUATVI:110:103:,,,:/home/oracle:/usr/bin/sh
tttt:V/X19.H/w5L6.:133:110:,,,:/home/tttt:/usr/bin/sh
kkkk:naIDu5DEtwiME:131:110::/home/kkkk:/sbin/sh
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: grep per GID

There are many ways but grep is probably not the answer (well grep -E maybe) but awk or Perl is much easier:

awk -F ':' '{ if ($4 == 110) print $0}' < /etc/passwd

The -F ':' makes a colon the field separator and we simply output the entire line ($0) when field 4 equals 110.
If it ain't broke, I can fix that.
tom quach_1
Super Advisor

Re: grep per GID

Thanks A. Clay

That would do it.

Regards,
Tom