Searching for patterns in files
grep [options] pattern [file-list]
Parameters
pattern is a regular expression,file-list is the list of path names for grep to search for plain text files
Options
-C displays only the number of rows in each file that contain a matching pattern
-V displays rows that do not contain a matching pattern
-I ignores case
-A in a binary file, search for data as a text file
-O shows only the content that matches RegExp (the number of times that the user statistics appear in the file)
-N matches the line number displayed at the beginning of the
-E extended grep, i.e. Egrep
-color=auto highlighting match keywords in a specific color
-A after means displaying data that matches a string and its following n rows
-B before, displaying data that matches a string and its first n rows
-C context displays the matching string and its front and back num rows
-W word search, equivalent to \b.
Example
Original file
1$CatTesta2 Aaabb3 BBBCC4ff-FF5 CCCDD6 Dddaa7$CatTestb8 AAAAA9 bbbbbTen CCCCC One ddddd A$CatTESTC - AAAAA - bbbbb theCcccc
grep
1 grep BB Testa 2 Aaabb 3 BBBCC
Searching for lines in Testa that contain the string bb
grep-v
1 grep -v BB testa2 ff-ff3CCCDD4 Dddaa
Searching for rows in Testa that do not contain matching strings
Grep-n
1 grep -n bb testa21: Aaabb32: BBBCC
Displays the line number of the matching row
grep *
1 grep BB *2testa:aaabb3testa:bbbcc4 testb:bbbbb
Search for matches in multiple files
grep-i
1 grep -I BB * 2testa:aaabb 3testa:bbbcc 4testb:bbbbb 5 testc:bbbbb 6 grep -I BB * 7testa:aaabb 8testa:bbbcc 9Testb : bbbbb testc:bbbbb
Case-insensitive matching
grep-c
1 grep -C BB* 2 Testa:23 testb:14 TESTC:0
Show only the number of rows matched in each file
15-grep Concise Pen