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.
Opt | What It Does | Example |
---|---|---|
-A n | Display n lines after the match | grep -A 3 Table * |
-B | Display n lines before the match | grep -B 3 Table * |
-c | Display only count of matched lines, not the text | grep -c Table * |
-C | Display two lines before and after the matching line | grep -C include * |
-i | Ignore case | grep -I Table report* |
-r | Search files in subdirectories also | grep -r Table * |
-v | Display lines that do not match | grep -v Error * |
-w | Match whole words only | grep -w Table *.txt |
-x | Match 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.