sed pattern to delete lines containing a pattern, except the first occurance

Hello sed gurus. I am using ksh on Sun and have a file created by concatenating several other files. All files contain header rows. I just need to keep the first occurrence and remove all other header rows.

header for file
1111
2222
3333
header for file
1111
2222
3333
header for file
1111
2222
3333

Should look like:

header for file
1111
2222
3333
1111
2222
3333
1111
2222
3333

I know how to remove lines matching a pattern, but I am brain-locking on the pattern needed to skip the first occurrence.

Removes lines starting with "header"

sed '/^header/d' filename

Thanks for any help!
Gary

an awk one:

 
awk '/header/&&c++>0 {next} 1' input_file
1 Like
sed '1!{/^header/d;}' inputfile

or

sed '2,${/^header/d;}' inputfile
1 Like
awk ' /^header/ && FNR > 1 {next} {print $0} ' infile > newfile
1 Like

Thanks ctsgnb I could net get that syntax for specifying the range to operate on.
Thanks to all for the different methods!
Gary

Is there a way to do this for multiple regex's? I have got part of it with sed:

sed '/pattern1/d;/pattern2/d;/pattern3/d;/pattern4/d' file > filetest

However, I didn't figure out how to skip the first instance of each pattern...

This one seems to double the data in the file...:

 awk '/pattern1/&&c++>0 {next} 1;/pattern2/&&c++>0 {next} 1' file > testfile

:confused:

awk '/header/&&c++ {next} 1'

but how do allow for more than one regex? /header/;/header2/;/header3/ ??

awk 'c++&&(/pattern1/||/pattern2/||/pattern3/) {next} 1'