Skip to content

Instantly share code, notes, and snippets.

@pmgupte
Created August 23, 2013 10:33
Show Gist options
  • Save pmgupte/6317849 to your computer and use it in GitHub Desktop.
Save pmgupte/6317849 to your computer and use it in GitHub Desktop.
# to get matching line and 5 lines before that
grep -B 5 "pattern" file
# to get matching line and 5 lines after that
grep -A 5 "pattern" file
# of course, you can combine -A and -B options together in single command. That's obvious.
# if your -A and -B values are same, you need not specify both the options. use -C instead.
grep -C 5 "pattern" file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment