Delete first block of text with sed/awk

Hello, guys!

"filename" has blocks with three lines each in this fashion:

93909286
    #verified
    has one bug
10909286
    #unverified
    pending
10909286
     #unverified
     pending

The above example has duplicate blocks, and I have tried using sed to remove just one block... The following piece of code removes all matching blocks, but I want to have only the duplicates removed:

sed -i '/^10909286$/,+2 d' filename

The following awk code has the same problem as the sed one, besides not being able to edit the file inline as "sed -i", but I could workaround it:

awk '/^10909286$/{c=3};--c<0' filename

Any ideas?

Thank you!

Try:

awk '!a[$0]&&/^[0-9]/{a[$0]=1;print;getline;print;getline;print}' file
1 Like

Hello, bartus, thanks!

I think I'm almost there: the file's got 3792 lines; with no duplicates (using sort -u | wc -l) it has 3378; and with your awk command it has 3384. So I think there are still two blocks remaining... Could you please explain a bit your code?

---------- Post updated at 09:38 AM ---------- Previous update was at 09:23 AM ----------

There are no errors in your code, thank you! There are duplicate lines, but no duplicate blocks!!!