Delete multiple lines starting with a specific pattern

Hi, just tried some script, awk, sed for the last 2 hours and now need help.

Let's say I have a huge file of 800,000 lines like this :

It's a tedious job to look through it, I'd like to remove those useless lines in it as there's a few thousands :

Or to be even more precise :
if line1 = UPDATE*
and line2 = SET LAST_UPD_TIMESTAMP=*
and line3 = WHERE*
then delete those lines

As I said, it's a huge file, the faster, the better. Thanks for any help.

sed "/UPDATE\|SET LAST_UPD_TIMESTAMP\|WHERE/d" infile

Use -i option to make the changes inline.

--ahamed

Thanks for answering that fast, however, it's not working as I really want it to be.

I don't want it to remove all the lines having UPDATE, SET LAST_UPD_TIMESTAMP and WHERE, only if they are close to each other on 3 lines. Any clue?

sed "/^UPDATE\|^SET LAST_UPD_TIMESTAMP\|^WHERE/d" infile

--ahamed

Unfortunately it produces the same exact results.

It should be like this :

Sorry, I missed that part of the requirement! Try this...

sed '/UPDATE/{N;/SET LAST_UPD_TIMESTAMP/{N;/WHERE/d}}' infile

--ahamed

1 Like

Thanks! sed is awesome, it's executing it so fast also, I really like it.