Linux study notes -- grep command (search string command)
Grep, which is used to search for strings that match the conditions in the file.
1. Command Format:
Grep [Option] string file name...
2. Common options:
"Grep-c" counts the number of rows matching the 'string' content. (C Indicates count.) "grep-I" ignores the case sensitivity. (I indicates ignore) "grep-l" prints a list of files matching the 'string' content. "Grep-n" prints the row number before the matched row. (N indicates line number) "grep-v" only displays unmatched rows. (V indicates reverse) "grep-w" full-character match search. (W indicates word regexp) "grep-A 4" outputs the rows matching the 'string' content and the last four rows. "Grep-B 4" outputs the rows matching the 'string' content and the first four rows. "Grep-C 4" outputs the rows matching the 'string' content and the first and fourth rows.
3. Common examples:
1) Find the row with 'exception' in the stdout1.log file.
2) Search for the number of rows with 'exception' in the stdout1.log file.
3) In the stdout1.log file, find the row with 'exception' and display the row number.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: SQL;"> 4) Find the row with 'exception' in the stdout1.log file, ignore the case and display the row number.
5) Find the row with 'exception' in the stdout1.log and stdout2.log files.
6) print out a list of files matching the 'string' content.
7) Search for lines with 'exception' and 'error' in the stdout1.log file.
8) in the stdout1.log file, find the rows with 'error' and the information of the first and fourth rows.