I’d prefer the answer to be either in php or perl since I have those easily at my disposal
The format of the file is as follows:
Name : ...
INSERT INTO (...) Values (...)
Name : ... <--- These are the lines I need
INSERT INTO (...) Values (...) <---
<span style='color:red;'>FAILED to INSERT ...</span>
Name : ...
INSERT INTO (...) Values (...)
...
The lines that are followed by the “FAILED to INSERT” span are the ones I’m interested in.
I’d like to remove all successful inserts and leave just the Name: and INSERT INTO parts of the lines that failed.
The “Name:” and “INSERT INTO…” parts are not necessarily on a single line.
This is my pseudo pattern that I think I need to match:
(/Name:/)(any character)(/INSERT INTO/)(anything but not /Name:/)(/FAILED to INSERT/)
Which would leave me with
Name: ...
INSERT INTO ...
<span ...> FAILED to INSERT
For each failed insert
I’m familiar with some regex basics, but could use some help with this one.
How might I do that in either perl or php?
Like Frits van Campen, regex can only be part of the solution, not the whole solution if you want to solve that quickly. I used some other logic as in his answer, because it was not fully correct: