2

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.

ShravanM
  • 323
  • 1
  • 7
  • 21
  • Why do you want to remove the first 6 lines? Including the `Report B566` it is only 5 lines to the first record –  Sep 18 '14 at 13:48

3 Answers3

0

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
jaypal singh
  • 74,723
  • 23
  • 102
  • 147
0

Sed solution

sed '/Report/,+4d' file

This removes the report line and the four following lines, it's a really simple command.

0

This might work for you (GNU sed):

sed -r '/Report/{G;/^(\S+\s+\S+\s).*\n\1/!{s/\n.*//;h;b};N;N;N;N;d}' file

Compare Report lines to the previous one and if they are the same remove it and the next five lines. If not the same store it and resume as usual.

potong
  • 55,640
  • 6
  • 51
  • 83