Get the Group name which has GID=0

1

I wanted to write a shell script in which it needs to give the group name whose GID=0.I used awk command like this,

awk -F ':' {$3==0} /etc/group | cut -d ':' -f1

It works fine in redhat,aix.But not worked in Solaris. It throws error like awk: syntax error near line 1 awk: bailing out near line 1

I want to use /usr/bin/awk in solaris.How to modify this script according to old awk in solaris?

or can i use alternate approach to generalize this script in all linux platforms?

user1507

Posted 2015-03-25T09:53:29.867

Reputation: 11

Try quoting the awk command script: awk -F ':' '{$3==0}' /etc/group …. – Scott – 2015-03-25T10:05:03.927

awk: syntax error near line 1 awk: bailing out near line 1 I tried that in solaris.It shows error like this. – user1507 – 2015-03-25T10:06:34.560

Is there any other command other than awk to get the output for this case? – user1507 – 2015-03-25T10:07:15.087

That was quick. … … … … … … … … You could probably use sed or perl. – Scott – 2015-03-25T10:08:23.280

can we able to check the condition like if GID=0 print the group name using sed? – user1507 – 2015-03-25T10:10:20.483

The answer is probably yes. – Scott – 2015-03-25T10:11:32.437

I am a newbee can you tell some outlined format to use sed to match this condition? – user1507 – 2015-03-25T10:15:27.583

Try doing some independent research: man, Google. Just searching Super User will yield a few nuggets (but also some gravel). – Scott – 2015-03-25T10:18:16.740

Answers

-1

Try using the below:

$ getent group "groupname"

or probably this might also work

$ awk -F':' '{ print $1 }' /etc/passwd

user3471740

Posted 2015-03-25T09:53:29.867

Reputation: 1

But the OP wants to find the group name given the GID (your getent command assumes that the group name is already known). And /etc/passwd is not a good place to get information about groups. – Scott – 2015-03-25T10:46:19.733

in aix getent is not available – user1507 – 2015-03-25T10:51:27.213