は、シェルを使用して、このような複雑な何かがしたい
コード:
$ 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
間違いなく、はるかに簡単な方法です( - Cオプションを使用する
のGNU 例えば、 (オ)はgrep )....
乾杯
ZB