grep command ~ Need help

Hello All

I am new to here and shell scripting ... and I need some help please

In /etc/group, how can I just grep the group that I want instead of the whole list? I just want "testabc", what do I have to do to get the "testabc" group information instead of all 4!

Thanks a lot for helping

For example:
In /etc/group
testabc
testabc1
testabc2
testabc3

Depend on the version of grep you are using.

Look in the man page

or try this
grep -w testabc /etc/group

Please post your OS-type

You can also quote your word with a trailing blank to get a literal query.

grep "testabc " /etc/group

:cool:

Hello again...

I use both Sun & HP OS

Thanks for the reply
I am not sure what I did wrong, but it doesnt work :confused:

May be I shouldnt use grep command? Any other suggestion?
What will be the best way to grab the "word (group name)" information alternately on the group in /etc/group?

Thanks again

testabc
testabc1
testabc2
testabc3

I would think that the -w trick would work on SunOS. Which version are you using?

But give this a try:
grep "^testabc:" /etc/group

When you are saying it doesn't work, do you mean that you can't get ONLY the first word? but instead get the whole line?

Then use this.

grep "^testabc" /etc/group |awk -F: '{ print $1 }'

This will give you ONLY the word "testabc".

Thank You All for Helping...
I think I Got it

:slight_smile: