I have a log file with a structure that follows:
- Timestamp header
- Log line
An example of such file as follows:
Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: --- Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: index: 14 timestamp: 1,590,170,100 value: 6 Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: delta totalA: 0 total: 5 totalA/total: 0 totalA/total/deltaC.length: 0 Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: bA index: 0 p: 294,325 b: 0 bb: 5 a: 0 aa: 0 total: 5 Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: positionX: 141 positionY: 39 Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: --- Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: index: 14 timestamp: 1,590,170,100 value: 6 Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: delta totalA: 0 total: 5 totalA/total: 0 totalA/total/deltaC.length: 0 Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: bA index: 0 p: 294,325 b: 0 bb: 5 a: 0 aa: 0 total: 5 Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: positionX: 141 positionY: 39 I would like to remove all timestamps except the ones followed by ---
--- Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: index: 14 timestamp: 1,590,170,100 value: 6 FINE: delta totalA: 0 total: 5 totalA/total: 0 totalA/total/deltaC.length: 0 FINE: bA index: 0 p: 294,325 b: 0 bb: 5 a: 0 aa: 0 total: 5 FINE: positionX: 141 positionY: 39 --- Jun 03, 2020 10:39:04 AM pacakge.subpackage.Class method FINE: index: 14 timestamp: 1,590,170,100 value: 6 FINE: delta totalA: 0 total: 5 totalA/total: 0 totalA/total/deltaC.length: 0 FINE: bA index: 0 p: 294,325 b: 0 bb: 5 a: 0 aa: 0 total: 5 FINE: positionX: 141 positionY: 39 I have tried this:
cat logFile.txt | awk -F':' '/$2=="---"/ {next; print $0; continue}; !/^FINE/ {next}; {print}' without success.
I am using FreeBSD 12.1 (csh, but I guess that is irrelevant as the right tool for this is awk, please correct me if I am wrong).
---. Am I wrong?