Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


    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`.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: