Using the shell, i'd do something convoluted like this
Code:
$ cat ./redlotus.sh
#!/bin/ksh
matchfile="redlotus.txt"
matches=`echo "${line}" | egrep -in "Error|Exception" ${matchfile}`
echo "${matches} " | while read line; do
lineno=`echo "${line}" | cut -d: -f1`
match=`echo "${line}" | cut -d: -f2`
echo "Match found - line ${lineno} - ${match}"
minline=$(( lineno - 5 ))
[[ "$(( lineno - 5 ))" -lt 1 ]] && minline=1
sed -n "$minline,$(( lineno - 1 ))p" ${matchfile}
sed -n "$lineno p" ${matchfile}
sed -n "$(( lineno + 1 )),$(( lineno + 5 ))p" ${matchfile}
# note we could just do
# sed -n "$minline, $((lineno + 5))p" ${matchfile}
# but i've left this as-is to show you how to grab the previous, and the
# next, five lines....
done
exit 0
No doubt, there is a far easier way (using -C option to GNU (e)grep for example)....
Cheers
ZB