How can I make ‘grep’ show a single line five lines above the grepped line?
OK, I think this will do what you’re looking for. It will look for a pattern, and extract the 5th line before each match. grep -B5 “pattern” filename | awk -F ‘\n’ ‘ln ~ /^$/ { ln = “matched”; print $1 } $1 ~ /^–$/ { ln = “” }’ basically how this works is … Read more