if grep -A
is not working, try
awk '/pattern/ {for(i=0;i<number_of_lines;i++){print;getline}}' <filename>
else sed has another dirty solution
sed -n '/pattern/ {p;n;p;n;p;...}' <filename>
here p-> print, n -> get to next line. So number of p is your number of lines to be printed
Update:
to use as a function, write in a test.sh
jobcheck(){
awk "/$1/"' {for(i=0;i<10;i++){print;getline}}' $2
}
then just
source test.sh
to run,
jobcheck "pattern" "file"
Update:
as per Jonathan Leffler's suggestion, if any of the next 10 lines contains the pattern, counting should start from that line so
pattern ->start printing from here to next 10 lines
blah
blah
pattern ->forget about the last 2 lines, start counting from here
blah
blah
So updated awk command will be like
awk '/pattern/{max_line=NR+2} {if(NR<=max_line) print}' <filename>
Similarly inside jobcheck will also be changed. Cheers:)