Print Surrounding Lines Around a Match
By default, the unix tool grep will only print the line that your keyword is found on. You can expand this behavior with the -A or -C flag.
grep -A 3 bob file.txt
prints the 3 lines after the keyword 'bob' is found in 'file.txt'
grep -C 3 bob file.txt
prints the 3 lines before and after the keyword 'bob' is found in 'file.txt'
In both cases, the line where 'bob' appears will still be printed.
Written by Miles Matthias
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Grep
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#