![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Simple newbie grep question | doubleminus | UNIX for Dummies Questions & Answers | 5 | 04-06-2008 03:05 PM |
| Ok simple question for simple knowledge... | Corrail | UNIX for Dummies Questions & Answers | 1 | 11-28-2005 09:03 AM |
| Simple grep - Not sure it makes sense! | GNMIKE | UNIX for Dummies Questions & Answers | 5 | 10-21-2005 11:51 PM |
| Simple grep question, but I'm out of practice | citygov | Shell Programming and Scripting | 0 | 08-02-2005 07:31 AM |
| Simple grep questions | nitin | UNIX for Dummies Questions & Answers | 2 | 10-14-2001 09:52 PM |
|
|
LinkBack | Thread Tools | Display Modes |
| Forum Sponsor | ||
|
|
|
|||
|
what that command does is just filter out any text containing 'grep'. for instance if you want to look at a log file,
$> cat 'somelogfile' | grep -v grep | less thats a pretty simple example, broken down, this is what it does, the command cat displays the contents of a file to the standard output. piping the cat 'somelogfile' to grep with the -v means to exclude anything entries thant contain the text 'grep' then piped to your pager, less, in this example. though cat is not really needed in that example, you could do it with just : grep -v grep 'somelogfile' | less thats the only thingi could think of right now. so really that second grep isnt a command just a string to be searched for, and in this case, filtered out. |
|
||||
|
To help with another example, it is usually used with the ps command.
For example, if you run 'ps -ef | grep sh' the output will contain all the running sh shells plus the 'grep sh' command itself. Now if you don't want to see the 'grep sh' in your ps -ef listing, you would run 'ps -ef |grep sh | grep -v grep' or 'ps -ef |grep -v grep| grep sh'. Both will have the same output, I am not sure if one will be faster then the other but if I had to guess I would say it is probably the first one because the 'grep sh' should shorten the list causing grep -v to have less to work with. |