Issue
I tried awk,grep and sed to parse the consecutive pattern as per below output but the result is null. only either of the pattern is working.
The awk '/^[0-9]/ && /OAA-/' file.txt
and grep -E '^[0-9].*ORA-' file.txt
The below input
2021-04-27T05:30:13.292507-04:00
OCC(3):
OCC(3):DB initialized.
OAA-06512: at "PATCH", line 001
2021-05-27T05:30:13.292507-04:00
OAA-06513: at "PATCH", line 002
OAA-06514: at "PATCH", line 003
2021-06-27T05:30:13.292507-04:00
This is the empty string.
Expected output
2021-04-27T05:30:13.292507-04:00
OAA-06512: at "PATCH", line 001
2021-05-27T05:30:13.292507-04:00
OAA-06513: at "PATCH", line 002
OAA-06514: at "PATCH", line 003
Could provide the syntax to parse the consecutive pattern like Date followed by OAA comment as per the expected output.
Solution
You may use this awk
:
awk '/^OAA-/ {if (dt) print "\n" dt; print; dt=""} /[0-9]{4}-/ {dt=$0} ' file
2021-04-27T05:30:13.292507-04:00
OAA-06512: at "PATCH", line 001
2021-05-27T05:30:13.292507-04:00
OAA-06513: at "PATCH", line 002
Answered By - anubhava Answer Checked By - Dawn Plyler (WPSolving Volunteer)