Skip to content

Instantly share code, notes, and snippets.

@cgorshing
Created January 22, 2014 21:46
Show Gist options
  • Save cgorshing/8567987 to your computer and use it in GitHub Desktop.
Save cgorshing/8567987 to your computer and use it in GitHub Desktop.
Find a pattern with grep but only print out 5 lines above the matching line.
grep -B5 "pattern" filename | awk -F '\n' 'ln ~ /^$/ { ln = "matched"; print $1 } $1 ~ /^--$/ { ln = "" }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment