grep | grep | grep .... better way ?

Cameron Hutchison lists at xdna.net
Sat Sep 22 21:48:59 UTC 2007


dave selby wrote:


>I am using a grep sequence of ..

>ps ax | grep motion | grep -v motion_watchdog.sh | grep -v grep

>is there a way for grep to be used without re-calling it with seperate
>-v's ? I dimly recal there is but man grep left me with a headache :)

One common pattern to remove that "grep -v grep" part is to put the
first character of the search pattern in brackets.

eg.

ps ax | grep '[m]otion' | grep -v motion_watchdog.sh

This will still grep for the string "motion" but that exact string does
not turn up in the grep command because of the brackets, so you do not
need to filter out grep.

You can probably further extend the regex in other ways (like putting a
$ at the end as previously posted) to have the pattern also not match
"motion_watchdog.sh", but since I don't know what other "motion"
processes you do want to match I cannot tell you the best way to make
the regex.





More information about the ubuntu-users mailing list