Name
grep [options] pattern [files] — grep
Synopsis
/bin stdin stdout - file -- opt --help --versionThe grep command is one of the most consistently useful and powerful in the Linux arsenal. Its premise is simple: given one or more files, print all lines in those files that match a particular regular expression pattern. For example, if a file contains these lines:
The quick brown fox jumped over the lazy dogs! My very eager mother just served us nine pancakes. Film at eleven.
and we search for all lines containing “pancake”, we get:
$ grep pancake myfile My very eager mother just served us nine pancakes.
grep can use two different types of regular expressions, which it calls basic and extended. They are equally powerful, just different, and you may prefer one over the other based on your experience with other grep implementations. The basic syntax is in Table 1-2 and Table 1-3.
Useful options | |
| Print only lines that do not match the regular expression. |
| Print only the names of files that contain matching lines, not the lines themselves. |
| Print only the names of files that do not contain matching lines. |
| Print only a count of matching lines. |
| In front of each line of matching output, print its original line number. |
| In front of each line of matching output, print the byte offset of the line in the input file. |
| Case-insensitive match. |
| Match only complete words (i.e., words that match the entire regular expression). |
| Match only complete lines (i.e., lines that match the entire regular expression). ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access