I have a logfile that I am trying to 'grep' data out of via a bash script. The data I am specifically after is all lines between two timestamps (including the top timestamp) that have the pattern "ERR-" and include an empty line after each entry for readability.
example logfile:
Tue May 24 21:22:12 2022
ERR-0045 Lock detected in /tmp/file.lck
Tue May 24 21:44:12 2022
Errors in file /tmp/filename01.trc:
ERR-0001: Error detected. /tmp/filename.log
Tue May 24 21:47:25 2022
im some output
Tue May 24 21:47:25 2022
im some output too
im some output aswell
Tue May 24 21:48:03 2022
Errors in file /tmp/filename09.trc:
ERR-0100: error
ERR-0050: failure of sorts.
ERR-0052: line 3421
Tue May 24 21:49:07 2022
Completed process xyz
So my desired output would look like :
Tue May 24 21:22:12 2022
ERR-0045 Lock detected in /tmp/file.lck
Tue May 24 21:44:12 2022
Errors in file /tmp/filename01.trc:
ERR-0001: Error detected. /tmp/filename.log
Tue May 24 21:48:03 2022
Errors in file /tmp/filename09.trc:
ERR-0100: error
ERR-0050: failure of sorts.
ERR-0052: line 3421
I have tried using combinations of sed/awk/cat without much success. Where I am having trouble is:
- It's not always two lines before ERR- which contains the timestamp
- There can be multiple ERR-'s in one timestamp block
- The date will obviously change so i don't want to hard code that in, although the format won't change.
Thanks in advance