Skip to content

Instantly share code, notes, and snippets.

@karthikselva
Created August 11, 2016 23:29
Show Gist options
  • Select an option

  • Save karthikselva/9a7bd967e86a331ff7360c3902435fde to your computer and use it in GitHub Desktop.

Select an option

Save karthikselva/9a7bd967e86a331ff7360c3902435fde to your computer and use it in GitHub Desktop.
Grep bunch of lines surrounding the hit

For BSD or GNU grep you can use -B num to set how many lines before the match and -A num for the number of lines after the match.

grep -B 3 -A 2 foo README.txt

If you want the same number of lines before and after you can use -C num.

grep -C 3 foo README.txt

This will show 3 lines before and 3 lines after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment