Home > database >  Move all lines between header and footer into new file in unix
Move all lines between header and footer into new file in unix

Time:06-02

I have file records like below, header, data & footer records.

I need to move only data part to another file. New file should only contain lines between Header2 and Footer1.

I have tried t head -n 30 fiename | tail 10 > newfile as data record counts may vary .

example records from source file .

Header1
Header2
Header3
SEQ  1
line1
line2
SEQ  2
line1
SEQ  3
line1
line2
line3
Footer1
Footer2
Footer3

Output file should have:

SEQ  1
line1
line2
SEQ  2
line1
SEQ  3
line1
line2
line3

CodePudding user response:

There are different ways.

grep:

grep -v -E "Header|Footer" source.txt

awk:

awk '! /Header.|Footer./ { print }' source.txt

You can replace the "Header" and "Footer" values by whatever you use to identify each lines.

  • Related