I want to use awk to print 5 lines before and 5 lines after the match regex (Start in ERROR and finish with on of INFO |WARN |DEBUG|TRACE). Also, I need to print the line number as well. I just success to print the line number
cat foo | awk '/\[ERROR\]/,/\[(INFO |WARN |DEBUG|TRACE)/{print NR":"$0}'
I don't care to find a solution with grep command
For example, the file contains:
DEBUG
DEBUG
DEBUG
TRACE
TRACE
INFO
INFO
ERROR
INFO
INFO
INFO
DEBUG
DEBUG
DEBUG
DEBUG
The output should be:
3: DEBUG
4: TRACE
5: TRACE
6: INFO
7: INFO
**8: ERROR
9: INFO**
10: INFO
11: INFO
12: DEBUG
13: DEBUG
14: DEBUG
The stars mark the match regex(Begin in ERROR, end in INFO)