# grep -b -A10 pattern file perl -ne '$c=11if/pattern/;$d=$c<11?"-":":";$t||=0;$c--,print"$t$d$_"if$c;$t=tell' file