Hi there,
I have a very large text file, from which I extract some strings and store them in a variable $a.
That variable $a looks like:
2013/09/20 16:45:59.285 [009] Collect finished
2013/09/23 08:17:58.678 [009] *** Collect CMI commands for system
2013/09/23 08:18:03.561 [009] Collect finished
2013/09/23 08:19:39.878 [023] Collect finished
2013/09/24 08:16:42.238 [009] *** Collect CMI commands for system
2013/09/24 08:16:49.430 [009] Collect finished
2013/09/24 08:17:53.052 [009] *** Collect CMI commands for system
2013/09/24 08:17:57.058 [009] Collect finished
2013/09/24 08:18:20.987 [023] Collect finished
2013/09/25 08:27:50.636 [009] *** Collect CMI commands for system
2013/09/25 08:27:59.528 [009] Collect finished
2013/09/25 08:45:12.290 [009] *** Collect CMI commands for system
2013/09/25 08:45:17.142 [009] Collect finished
2013/09/25 08:47:17.060 [023] Collect finished
Now I would like to somehow select only the lines containing the text “Collect CMI commands for system” together with the very next line.
So my goal is to obtain this:
2013/09/23 08:17:58.678 [009] *** Collect CMI commands for system
2013/09/23 08:18:03.561 [009] Collect finished
2013/09/24 08:16:42.238 [009] *** Collect CMI commands for system
2013/09/24 08:16:49.430 [009] Collect finished
2013/09/24 08:17:53.052 [009] *** Collect CMI commands for system
2013/09/24 08:17:57.058 [009] Collect finished
2013/09/25 08:27:50.636 [009] *** Collect CMI commands for system
2013/09/25 08:27:59.528 [009] Collect finished
2013/09/25 08:45:12.290 [009] *** Collect CMI commands for system
2013/09/25 08:45:17.142 [009] Collect finished
I tried regular expressions, but I can’t figure out how to use the carriage return character.
This is what I tried:
$regex = “.Collect CMI commands for system.(\r.*)”
$a -match $regex
That regular expression should return the line containing the specific text and its consecutive line.
But this doesn’t return anything…
Well, then I thought that this text is not really a string, but it’s an array. Still, how can I filter the array to obtain the same text I already mentioned?
Thank you!