How do I print from a specific string to a new line with a matching pattern
How do I print from a specific string to a new line with a matching pattern
(OP)
Hi,
I have a log file I want to parse. Lines normally begin like this:
2022-04-07 12:46:14,624-0400 some text here
2022-04-07 12:46:14,625-0400 some more text here
2022-04-07 12:46:14,625-0400 ERROR something
oh my gosh
this is terrible
bad error message
2022-04-07 12:46:14,625-0400 some more text here
2022-04-07 12:46:14,625-0400 some more more text here
I want to capture from the beginning of an error line until the next new line with the timestamp.
What I tried to do is this:
awk '/ERROR something/,/^2022/' mylog.txt
But this didn't work because the pattern match works on my first line. I want to find the next line with the string ^2022, so basically print the current line until the next line of ^2022.
The desired output would be:
2022-04-07 12:46:14,625-0400 ERROR something
oh my gosh
this is terrible
bad error message
Thanks in advance!
I have a log file I want to parse. Lines normally begin like this:
2022-04-07 12:46:14,624-0400 some text here
2022-04-07 12:46:14,625-0400 some more text here
2022-04-07 12:46:14,625-0400 ERROR something
oh my gosh
this is terrible
bad error message
2022-04-07 12:46:14,625-0400 some more text here
2022-04-07 12:46:14,625-0400 some more more text here
I want to capture from the beginning of an error line until the next new line with the timestamp.
What I tried to do is this:
awk '/ERROR something/,/^2022/' mylog.txt
But this didn't work because the pattern match works on my first line. I want to find the next line with the string ^2022, so basically print the current line until the next line of ^2022.
The desired output would be:
2022-04-07 12:46:14,625-0400 ERROR something
oh my gosh
this is terrible
bad error message
Thanks in advance!
RE: How do I print from a specific string to a new line with a matching pattern
you can try something like this
johngiggs.awk
CODE
On the data file you provided
johngiggs.txt
CODE
the output of the script above is:
CODE
RE: How do I print from a specific string to a new line with a matching pattern
Thank you for that suggestion. It did work for the example, however my example wasn't clear enough. There are some WARN lines that I want to ignore. I want to capture ERROR and the subsequent lines below it until the next new line with a datestamp.
2022-04-07 12:46:14,624-0400 some text here
2022-04-07 12:46:14,625-0400 some more text here
2022-04-07 12:46:14,625-0400 ERROR something
oh my gosh
this is terrible
bad error message
2022-04-07 12:46:14,625-0400 some more text here
2022-04-07 12:46:14,625-0400 some more more text here
2022-04-07 12:46:14,625-0400 WARN something else goes here
2022-04-07 12:46:14,625-0400 ERROR something
oh my gosh
this is terrible
bad error message
2022-04-07 12:46:14,625-0400 some more text here
2022-04-07 12:46:14,625-0400 some more more text here
Thanks!
RE: How do I print from a specific string to a new line with a matching pattern
it works too with the another input file:
CODE