I have a very large log file (6 gig).
I want to search for 'Nov 12 2012' and print off each line.
I'm a linux novice and have no idea how this is done. Mostly likely will need a more option to view X number of lines and move forward thru the search.
The grep command prints entire lines when it finds a match in a file. To print only those lines that completely match the search string, add the -x option. The output shows only the lines with the exact match.
To also show you the lines before your matches, you can add -B to your grep. The -B 4 tells grep to also show the 4 lines before the match. Alternatively, to show the log lines that match after the keyword, use the -A parameter. In this example, it will tell grep to also show the 2 lines after the match.
With grep -i -n 'string' you can search for a particular string and find out what line it is on.
grep --after-context=5 --before-context=10 'Nov 12 2012' yourfile.log
That'll show each line that contains your date text, as well as 10 lines of text BEFORE the line that matched, and 5 lines AFTER the line that matched.
You can use grep
to show matching lines and less
as a pager:
grep 'Nov 12 2012' /path/to/logfile | less
Type 'space' at the end of each page to advance to the next screen of results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With