I have a file called source.txt which contains the following lines:-
the
quick
brown
fox
jumped
over
the
lazy
dog
I want to search for the 'fox' line and delete it and all lines that follow, up to and including the 'over' line. Then I want to insert the contents of another file (fruit.txt) in place of those lines. Fruit contains:-
apples
bananas
pears
So the result should be a file that looks like this:-
the
quick
brown
apples
bananas
pears
the
lazy
dog
I think this will be possible to do using the sed command.
This command successfully removes the lines:-
sed -i -e '/fox/,/over/d' source.txt
And this command almost works, but inserts the contents of the fruit.txt file three times, once for each matching line:-
sed -i -e '/fox/,/over/{r fruit.txt' -e 'd}' source.txt
Any help would be greatly appreciated!