Hopefully some of you awk jockeys also dabble a bit in sed... I am trying to use a bit of both on a project and this task seemed more suited to sed but if awk is better I am game.
I have been trying to write a little sed script that would allow me to remove a header record that gets repeated when I concatenate a group of similar data files... all the header lines begin with "first name" so I gave this a try...
1{
h
d
}
/^first name/!{
H
d
}
g
This saved off the first line (the header I want to keep) into the hold space and then looped through the file appending the records to the hold until it hit the first repeated header and it spit out the results... so I added
/^first name/d just above the g to kill off the next header and it killed off everything... I get no output at all. What I want it to do is send the repeats of the header to the bit bucket and keep appending the records to the hold space until the end of the file is reached and at that point output the contents of hold. This utility would probably be better if I blew off using the hold space and just sent the first line and all subsequent non header lines to stdout... it would tie up less memory but i have not figured out how to do that.
I have been trying to write a little sed script that would allow me to remove a header record that gets repeated when I concatenate a group of similar data files... all the header lines begin with "first name" so I gave this a try...
1{
h
d
}
/^first name/!{
H
d
}
g
This saved off the first line (the header I want to keep) into the hold space and then looped through the file appending the records to the hold until it hit the first repeated header and it spit out the results... so I added
/^first name/d just above the g to kill off the next header and it killed off everything... I get no output at all. What I want it to do is send the repeats of the header to the bit bucket and keep appending the records to the hold space until the end of the file is reached and at that point output the contents of hold. This utility would probably be better if I blew off using the hold space and just sent the first line and all subsequent non header lines to stdout... it would tie up less memory but i have not figured out how to do that.