Search this site


Metadata

Articles

Projects

Presentations

grep -A (after), -B (before) context without gnu grep (-C too...)

This essentially does grep -C 5 REGEX $FILE. This was a boredom-induced hack
FILE=foo.log
grep -sn REGEX $FILE | \
awk -F: '{print $1}' | \
xapply -f 'A=$((%1-5)); B=$((%1+5)); echo "-----"; \
   sed -ne "${A},${B}p" '$FILE'; \
   echo "---"' -