I want to do server.log analysis for error and i want before 10 line and after 10 line of that error so below script is giving error in Hp-ux,please provide alternate solution:
grep -A 10 -B 10 "ERROR" server.log >> /tmp/Test.log
I want to do server.log analysis for error and i want before 10 line and after 10 line of that error so below script is giving error in Hp-ux,please provide alternate solution:
grep -A 10 -B 10 "ERROR" server.log >> /tmp/Test.log
Hope this helps
grep -A10 -B10 -P "ERROR" server.log >> /tmp/Test.log
Since the old grep
hasn't the convenient -ABC
options, the solution is a little more complicated:
grep -n "ERROR" server.log | sed 's/\([0-9]*\):.*/\1-10<=NR\&\&NR<=\1+10{print;next}/' \
| awk -f- server.log >>/tmp/Test.log
This uses sed -n
to get the line numbers and a sed
-generated awk
script to print the context.