grep (find text in files)

Searches one or more files for text that matches regular expressions. The grep command is described in Chapter 7.

Format:    grep pattern filelist
Examples:  grep "^Table [0-9]:" *

Displays each line that matches the regex. The filename and line number is listed.

OptWhat It DoesExample
-A nDisplay n lines after the matchgrep -A 3 Table *
-BDisplay n lines before the matchgrep -B 3 Table *
-cDisplay only count of matched lines, not the textgrep -c Table *
-CDisplay two lines before and after the matching linegrep -C include *
-iIgnore casegrep -I Table report*
-rSearch files in subdirectories alsogrep -r Table *
-vDisplay lines that do not matchgrep -v Error *
-wMatch whole words onlygrep -w Table *.txt
-xMatch whole lines only ...

Get Spring Into Linux® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.