grep

grep is a tool to extract text lines from files (or command outputs using pipes). You’ll use it without end once you’ll know how to do!

$ grep pattern from_file

$ cat from_file | grep pattern

$ some_command_text_output | grep pattern

The pattern may be of various formats, of which plain text or regexp.

Some options may change the behaviour of grep:

$ grep -i pattern from_file

will extract the lines matching pattern without matching the case

$ grep -v pattern from_file

will extract the lines not matching the pattern

$ grep -r pattern from_files

recursively looks in a directory and all his subdirectories

Some tools with other similar names are just quick access to some options of grep, like egrep or rgrep(recursively looks in a directory and all his subdirectories).

This article was first written in July 2003 for
the BeezNest technical website (http://glasnost.beeznest.org/articles/47)
It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on TumblrEmail this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *