Hacker News new | ask | show | jobs
by geocrasher 1287 days ago
One thing I didn't see was how to use GREP to view the lines before and after a match:

   grep regex /var/log/logfile -A5 #To view the next 5 lines
   grep regex /var/log/logfile -B5 #To view the previous 5 lines
   grep regex /var/log/logfile -05 #To view the 5 lines before *and* after the match
This is super handy to find out what happened just before a service crashed, for example.
1 comments

    grep regex /var/log/logfile -05 #To view the 5 lines before *and* after the match
This appears to work with GNU grep, at least, but YSK that the POSIX grep option for this is `-C`.