Bash and grep

From I Will Fear No Evil
Revision as of 10:10, 8 July 2024 by Chubbard (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Common grep switches

Show line number of match

grep -n <string> <file(s)>

Insensitive match

grep -i <string> <file(s)>

Before and after # lines from match

grep -A# -B# <string> <file(s)>

Regex example

grep -iE 'app[-]?(blue\|green)?'

Will match:
app
app-blue
app-green