Grepping around the match

So, you want to dig into your huge logfile, you know that the information you are searching contains a piece of data, but you also want the context around it. Definetly not good to load the entire log file into memory, if it’s too big. Also, not very convenient to search manually using an editor. What do you do?

Use grep:


$ grep /path/to/file -An -Bn

Where n is an integer. -A specifies the number of lines to be printed after the match, and B does for the lines before, as you might have guessed.

Pretty useful.

Leave a Reply