#!/bin/rc # cgrep - context grep # NB: /dev/null in list of files to force printing source # files when there is just one file supplied grep -n $* /dev/null | sed 's/^(.*):([0-9]*): .*$/\1 \2/' | while(loc=`{read}){ echo $loc(1)^:$loc(2) start=`{echo 'if(' $loc(2) ' > 2) print(' $loc(2) ' - 2) else print 0' | hoc} tail -n +^$start $loc(1) | sed 's/^/ /; 6q' }