Search code examples
unixawksedgrephp-ux

How to remove series of lines in a file on hp unix using awk or sed or grep


My report looks like:

Report B566  company name .................................... Page 1

    Name    address   pin   


    John    ny        1111
    Dave    ma        1112
    ....    ....    ....   
    ....    ....    ....   
    ....    ....    ....   
Report B566  company name .................................... Page 2

    Name    address   pin   


    Barry    CA        5111

This way i have around 100 pages, i want to get rid of repetitive headers. i need a command in such way that if "Report B566" is found in the file all of them along with the next 6 lines should be removed and the outfile should contain only the data.

I'm working on HP-UNIX box. (ksh)

Thanks for your help.


Solution

  • You can set a counter and print based on when the counter is true.

    $ awk '/Report/{c=6}!(c&&--c)' file
    John    ny        1111
    Dave    ma        1112
    ....    ....    ....
    ....    ....    ....
    ....    ....    ....
    Barry    CA        5111