May 25, 2009

Don’t grep grep!!!

Posted in Tips tagged , , at 10:20 pm by Karel MALBROUKOU

Well well, a linux user / admin who has a little respect for himself has to know that tool: grep.
Used for string searching, we can use it on the output of a command using the pipe character.
But, what happened when you do: ps x | grep firefox??

And yes, grep will grep himself:
$ ps x | grep firefox
8902 ? SNLl 59:29 /usr/lib/mozilla-firefox/firefox
9426 pts/9 SN+ 0:00 grep --colour=auto firefox

How could we fix this little cutie issue. We could use a sed… Yeah … or a head maybe… not that great either.

Or, we could hack grep!
Instead of using ps x | grep firefox, try ps x | grep [f]firefox!

Tell Me More!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: