I have the following problem... I have a file, similar to this one:
2018-04-25: line1
2018-04-25: line2
this is another line
I'm a line
2018-04-25: line3
2018-04-25: line4
If I run: grep 'this' test.log the result will be:
this is another line
but I need the result to be:
2018-04-25: line2
this is another line
I'm a line
because 'this is another line' is actually part of the same entry the only problem is that we have a break line there and I need my grep to ignore this break line.
- grep -C 1 'this' test.log
- grep -B 1 'this' test.log
are not really an option because I might have more lines/break lines between the start of the entry and the end.
Here's one way using GNU awk: the date at the start of the line is the record separator. For the record containing the pattern, print the previous record separator and the current record.
Or, more straightforward