grep, which finds the meaning of a string, is to match a qualifying string in a file.
1. Command format:
...
2. Common options:
"Grep-c"Statistics Match to' String 'The number of rows for the content. (c is the meaning of count)"Grep-i"ignores case differences. (I for the meaning of ignore)"Grep-l"Print out matches to' String 'The list of documents for the content."Grep-n"Prints the line number in front of the matching line. (N is Line Numbermeaning)"Grep-v"Only rows that do not match are displayed. (V for the meaning of reverse)"Grep-w"Search with whole word matching. (W isWordThe meaning of RegExp)"Grep-a 4"Output matches to' String 'The contents of the line and after4Yes."Grep-b 4"Output matches to' String 'Line and front of content4Yes."Grep-c 4"Output matches to' String 'Lines of content and before and after4Yes.
3. Common examples:
1) 在stdout1.log文件中查找有‘exception‘的行。
2) 在stdout1.log文件中查找有‘exception‘的行的数目。
3) 在stdout1.log文件中查找有‘exception‘的行,并显示行号。
4) 在stdout1.log文件中查找有‘exception‘的行,忽略大小写并显示行号。
5) 在stdout1.log和stdout2.log文件中查找有‘exception‘的行。
6) 打印出匹配到‘字符串‘内容的文件清单。
7) 在stdout1.log文件中查找有‘exception‘和‘error‘的行。
8) 在stdout1.log文件中查找有‘error‘的行和前后4行的信息。
Linux Learning Note--grep command (search string command)