------------------------------------------------------------------------ g/re/p Global search specified by /re/ and print ------------------------------------------------------------------------ grep "string" filename search for string in filename. print matching line grep 're' filename search for regular expression in file name. print matching line note that "re" is NOT enclosed by "/" (as in sed) grep -R pattern * recursive search for pattern from curent level and below grep -v pattern infile display lines which do NOT match pattern grep -i pattern infile display lines which match pattern regardless of case grep -n pattern infile display matched line(s) followed by the line number(s) grep -c pattern infile count number of occurrences of pattern in "infile" grep -l pattern file* display the names of files containing pattern grep -o pattern infile displays not the line but the matches to pattern grep -e pattern file useful when pattern contains "-" grep -e pattern1 -e pattern2 file specify multiple patterns for searching %-------contextual search----------------------------------------------- grep -A n pattern infile display matched line and "n" lines AFTER matched line grep -B n pattern infile display matched line and "n" lines BEFORE matched line grep -C n pattern infile display matched line and "n" lines CENTERED on matched line %----------------------------------------------------------------------- grep -w pattern infile display lines containing word stated by pattern grep \ infile does the same as as "-w" grep pattern\> infile display lines in which word ending is given by pattern grep \