| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
On 26 Jan 2015 13:56:47 -0800, "[email protected] [sed-users]"
<[email protected]> wrote:
> In our log files, we have some SQL output that looks roughly like:
>
>
> DROP <more text>
>
>
> ERROR
>
>
> This 3 line sequence is seen throughout the log files, but we don't
> care about these type of errors.
> The first line if the 3-line pattern begins with DROP,
> the second line is mostly but not necessarily empty (assume it can be
> any text), the 3rd line begins with ERROR.
>
>
> What I'd like to be able to do is make a copy of the log file,
> the run sed to find any line that begins with DROP followed
> by a line followed by a line that begins with ERROR, and remove
> all 3 lines. Repeat that action for any match of this 3-line pattern.
> This is on Linux using bash.
This is a FAQ, see http://sed.sourceforge.net/sedfaq4.html#s4.23, so
adapting the second solution in 4.23.2 you can do (adapt the RE in the
penultimate line to your exact needs)
: more
$!N
s/\n/&/2;
t enough
$!b more
: enough
/^DROP.*\n.*\nERROR$/d
P;D
Put the above in a file, eg prog.sed then run
sed -f prog.sed logfile.log
--
D.