by geocrasher · 3y ago · 0 comments
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`.