https://www.youtube.com/watch?v=VGgTmxXp7xQ
Code: Select all
grep "John Williams" names.txt
-i ignore case
-v invert match
-w select only those lines containing matches that form whole words
-n line number
-B 2 +two lines before
-A 3 +three lines after
-C 2 +two before and after line (context)
-l search and list filenames contains it
-c counts matches
-P regular expressions
Code: Select all
grep -win "John Williams" ./* search in all files in the directory (no subdirs)
grep -win "John Williams" ./*.txt search in all txt files in the directory (no subdirs)
grep -winr "John Williams" ./*.txt search in all txt files in the directory (subdirs with r option, recursive)
grep -wirl "John Williams" . search and list filenames contains it (l option, list files)
grep -wirc "John Williams" . search and counts matches in every file
grep -P "\d{3}-\d{3}-\d{4}" names.txt