Free BSD/ Mac OS X Sed: Print regex match and the line 5 lines after the match

sedtext processing

I thought it would be sed -n /mymatch/,+5p but I get expected context address. At this point I am just guessing commands, nothing works! I want to grab every line that matches the regex and print that line and the line which comes 5 lines after it, globally from a file.

Best Answer

Might be easier with awk:

awk '/foo/ {print; p[NR+5]; next}; NR in p'
Related Question