Hello,
If I have a Text in a Textfile like this:
WARNING: Blablabla first line
blablablabla second line.
and I try it like this:
(get-content file) -match "^WARNING:"
I only get the first line.
What regular expression would include the second line ??
Hi there
Would you copy and paste the content, and the result that you would like to get of it?
Would you like the first and second lines only, out of an N amount of lines, perhaps?
Cheers.
D.
You can take the example I wrote in my qestion:
So it usually looks like this:
Some other Text Some other Text Some other Text Some other Text
I just want the "WARNING:*" + next line bits.......
you could try something like this:
PS> select-string $env:windir\windowsupdate.log -context 0,1 -Pattern 'WARNING'
This gives you back every line that has a "WARNING" and the immediately following line.
If you prefer to process the results from code, here's a sample that extracts the keyword line and then the following line, so you can do whatever you want with them:
select-string $env:windir\windowsupdate.log -context 0,1 -Pattern 'WARNING' | ForEach-Object { "Line with keyword: " + $_.Line "Following line: " + $_.Context.PostContext[0] }
As always, Tobias has solved the riddle !!
Thank you very much!