Blogger

Delete comment from: Javarevisited

Anonymous said...

Hi Javin, thanks for this, much appreciated! I would like to share two more grep goodies I am frequently using:

- grep -A x adds x lines to each matching line. Useful for finding information for which the match is only the headline.

- In order to prevent grep from finding itself f.e. in ps -ef output or in the history, use square brackets around the first character. This regular expression tricks grep into searching for the wanted string while the string itself does not occur in the command. Example:

ps -ef | grep [j]ava

shows all running java processes while it will not show 'grep java' in the result. Much less typing than

ps -ef | grep java | grep -v grep

and one process less in the pipe.

Kind regards,
Ralph Kirchner

Jul 9, 2012, 6:40:20 AM


Posted to 10 examples of grep command in UNIX and Linux

Google apps
Main menu