Reputation: 43
I'm trying to clean up the output from someone else's script by removing the headers that have no content.
Output currently looks like this:
====== Header1 ======
====== Header2 ======
====== Header3 ======
information
I'm trying to remove the lines for Header1 and Header2, but not Header3. I found an awk command that removes all duplicate lines but the last that begin with the same character, so that helps for this issue, but causes a new problem when the 'information' bit is numerous lines that also begin with the same character (usually tabs).
Desired output post cleanup:
====== Header3 ======
information
Thanks
Upvotes: 2
Views: 75
Reputation: 33327
This awk might work for you:
$ awk '/^===/{h=$0;p=0;next}!p{print h};{p=1}1' file
====== Header3 ======
information
Or as Glenn pointed out, this also works:
awk '/^===/{h=$0;next}h{print h;h=0}1' file
Upvotes: 1