Files get messed up with multiple lines containing foo
or bar
. I want to remove all of them and append one line of each at the end.
So, given a file
some stuff
foo1
foo2
bar=42
some other stuff
bar
foo
more stuff
the sed script should return
some stuff
some other stuff
more stuff
foo
bar
I tried with sed '/foo/d;/bar/d;$s/$/\nfoo\nbar/'
which works as long as the last line contains neither foo
nor bar
and the file is not empty.
How to do make it work even with foo
in the last line? I'd like to stick to sed, becuase the whole script should do more than just this. Of source I could append my lines with echo after the script, but I wonder if there is no all-in-one-solution.
Edit: The empty file case doesn't need to be handled.