Skip to main content

Grep

The whole docs section is work in progress. Feedback is highly welcome.

Off. documentation:
https://www.gnu.org/software/grep/manual/grep.html
tested Version:
Grep 3.4

General

Syntax

grep [option...] [patterns] [file...]

My most used Options:

-r:
Recursivly search directory
-v:
Reverse search
-c:
Displays only the count of matching lines
-n:
Shows the matching line and its number
-i:
Match both upper and lower case
-I:
Process a binary file as if it did not contain matching data
-l:
Shows just the name of the file with the string
-x:
Shows only exact matches
Show addtional lines above and below matching line:
-A 1 - Show x lines above
-B 1 - Show x lines below
-C 1 - Show x lines above and below

Patterns

"/' around patterns are often enough not required

Only show result of pattern is at the start of the line:
^pattern
Only show result if pattern is at the end of the line:
pattern$
Look for special characters like -:
grep '\-c'
(\ is the escape character)
grep -- '-c'
(-- flag to stop switch parsing)
Search multiple patterns
Grep OR:
grep -E "pineapple|pizza" file.txt
grep -e pineapple -e pizza file.txt
grep 'pineapple\|pizza' file.txt
Grep AND:
grep 'pizza' file.text | grep 'pineapple'
grep -E 'pizza.*pineapple' file.text (In order)
grep -E 'pizza.*pineapple|pineaple.*pizza' file.text

Usage

Examples

Coming soon: logs, manuals, tests


Helpful links

WIP

Todo:
Add examples for flags
Examples with regex
Link to grep blog posts
Link to the source for comments/ changes
Go through bookmarks and add helpful links


You can contact me via ...