Bash and grep

From I Will Fear No Evil
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