Therefore, a command that can quickly locate the log to be analyzed is needed!
And grep is very suitable!
Basic usage
grep string2search filename #Search file content and return lines containing string2search
However, string2search is only used to locate, and the content that really needs to be analyzed is around the line! ! ! !
Therefore, the -B and -A options are needed,
such as
grep -B n -AN string2search filename #Display the contents of the first n lines to the last N lines of string2search
What if I find too many logs? Coupled with the redirection command it's perfect:
grep -B n -AN string2search filename >output.txt #Output the contents of the first n lines to the last N lines of string2search to output.txt
In addition, you can also use the sed command to replace the content in the file for easy display
grep string2search filename | sed "s/\a/, /g" #Replace the bell character with, easy to view
Recursive query (query under a folder):
grep -r string2search
See: http://stackoverflow.com/questions/9081/grep-a-file-but-show-several-surrounding-lines