LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Grep Commmand (https://www.linuxquestions.org/questions/linux-general-1/grep-commmand-556279/)

sachinh 05-24-2007 01:33 AM

Grep Commmand
 
Our requirement is to grep a particular user in /etc/passwd .

grep test /etc/passwd

But the above command will match the user test as well as test123( if present).

We just want to match the exact word given in grep statement.
Is there any parameter for this ??

druuna 05-24-2007 01:40 AM

Hi,

Use the -w option (grep -w test /etc/passwd

Hope this helps.

sachinh 05-24-2007 01:50 AM

Quote:

Originally Posted by druuna
Hi,

Use the -w option (grep -w test /etc/passwd

Hope this helps.


Thanks DRUUNA ...it worked.... Wonder how one can remember all the switches in UNIX ??

druuna 05-24-2007 01:51 AM

Hi,

You're welcome.

Quote:

Wonder how one can remember all the switches in UNIX ??
That's why they created man and info pages ;)

sachinh 05-24-2007 01:56 AM

Quote:

Originally Posted by druuna
Hi,

You're welcome.


That's why they created man and info pages ;)


U r RIGHT ...but if you go to man page for grep .... its very difficult to search for the correct switch as is the case with -w switch.
The explaination given for -w is difficult to understand and realise , if this is the correct option we are lookin for. :-)

jschiwal 05-24-2007 02:01 AM

You could also add a colon to the search term, since that is what is used to separate fields in /etc/passwd.


All times are GMT -5. The time now is 04:25 PM.