Brug af skallen, ville jeg gøre noget højtravende som dette
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
Ingen tvivl om, at der er en langt nemmere måde (med-C mulighed for at
GNU (e) grep for eksempel )....
Skål
ZB