GNU Grep Cheatsheet
GNU Grep Cheatsheet
DEVHINTS.IO Edit
Usage
GNU grep cheatsheet Matching opt
grep <options> pattern <file...> -e, --regexp=
-f, --file=FI
-i, --ignore-
Perl Compatible R
PCRE has even
-B NUM, --before-context=NUM # print NUM lines before a match
-A NUM, --after-context=NUM # print NUM lines after a match
-C NUM, -NUM, --context=NUM # print NUM lines before and after a match conditional exp
Examples
# Case insensitive: match any line in foo.txt
# that contains "bar"
https://devhints.io/grep 1/3
6/28/23, 1:59 PM GNU grep cheatsheet
grep -i bar foo.txt
Devhints home
https://devhints.io/grep 3/3