Grep

Searches input files selecting line to match patterns with

grep [opts] [re] [file]

grep jorge test.txt 
#same as 
grep "jorge" test.txt

Use \ to escape characters

Search Directory

grep -r "\"Help.*me\"" .

Count number of lines with the word test in it

grep -r phone . | wc -l

Some Options

Flag

Does

-o

only print matching part of line

-n

output line #s too

-r

search recursively subdirs

-i

case insensitive

-v

select the non-matching lines

-E

Use extended grep(see below)

-F

Fixed string matching(faster if not re)

-C [n]

n lines shown b4 and after match

Extended Grep

Allows you to do stuff like specific or ranges of repetitions

Not

Range

Or

Other Tools

https://beyondgrep.com/feature-comparison/

ack, ag, git grep, ripgrep

Last updated