Grep

From TBP Wiki
Revision as of 14:35, 5 January 2019 by Goldbolt (talk | contribs) (Created page with "grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a match to the given...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN. By default, grep prints the matching lines. grep is a powerful tool.

Using grep

Recursively search DIR for "STRING" (also ignores caps)

    grep -ri "STRING" /DIR/

Piping

grep can also be piped from or to other outputs using the pipe "|"

   grep "STRING" /LOCATION/logfile.log |grep ANOTHERSTRING

Example usage:

   grep "13:00:" /var/log/messages |grep "September"
   tail -f /var/log/somefile.log |grep specificstring