print specific line and then some more
I am trying to search a file for a pattern and if the it is found I want to see the line and 10 more lines of the result.
so far I have
grep -n pattern file | cut -d: f1
now not sure how to use this out put to do the print with the logic like
sed -n result,(result+10)p file
probably going to have a few issued if it pattern is in multiple lines.
Any help is appreciated
Using grep 2.10:
grep -A 10 "pattern" your_file
will print 10 lines after the match
From the grep man page:
-A num
--after-context=num
Print num lines of trailing context after matching lines.
Using GNU awk 3.1.8:
awk '{if(a-->0) {print; next}} /pattern/{print; a=10}' your_file