get information out of large log-file

Hello,

as described in the title, i need some help getting some information from several log-files.
These files are part of a testbench where all tests and many other information are stored.
The format of these files is as following:

2020-10-23 11:25:39:1000 [WARNING] some other stuff
2020-10-23 11:25:39:1000 [WARNING] SerialNumber:123456
2020-10-23 11:25:40:1000 [WARNING] some other stuff
2020-10-23 11:25:40:1000 [WARNING] some other stuff
2020-10-23 11:25:40:2000 [INFO] measurement started
2020-10-23 11:25:41:3000 [INFO] measurement finished
2020-10-23 11:25:41:1000 [WARNING] some other stuff
2020-10-23 11:25:41:1000 [ERROR] and so on

Searching for the string “measurement started” is simple… but i also need the serial number which is in one of the lines above.
Unfortunately, the number of lines between Serial and measurement is not always the same…

I have tried it using Add-Content/Get-Content; i tried it using loops… and nothing worked for me…

Any ideas?

Thanks in advance

Select-String -Pattern "SerialNumber:\d+","measurement started" -Path E:\myLog.txt | Select -ExpandProperty Line

Output:

2020-10-23 11:25:39:1000 [WARNING] SerialNumber:123456
2020-10-23 11:25:40:2000 [INFO] measurement started

 

wow… thank you very much… this works as expected :slight_smile: