The grep command

The grep command



What does it do ?

Grep searches a file for occurances of a search pattern given by the user. By default all lines which contain the search pattern are displayed.


How is it used ?

grep pattern filename
grep options pattern filename
grep options -f filename filename
OPTIONS:
-b Display byte offset within each file before each line of output
-f filename Use file filename as search pattern
-n Prefix each line of output with the line number within its input file.
These are only a few of the options avaible for grep.To learn about other options use man grep or grep --h.


Examples and remarks

Perhapes you needed to see every line in a piece of code (called myfile.c) which contained the varible test you could do the following.

grep test myfile.c

Perhaps after writting a paper you discover you misspelled dog as dig you could use the grep command to find all of the lines where you typed dig instead of dog.

grep dig termpaper.doc

Grep can be used for many different things in many different ways which will assist you in you work and play.



next previous table of contents