@apophis i wouldn't know but to me it sounds like this could be done with awk
โ cat fileAAnyways if you don't want to write your own script and would rather have a shell script with sed and such, you should probably do something similar to what I did:
hello
world
how are you doing on this fine day
I am doing quite START fine
what about you?
oh yeah whatever
blabla END
honestly i dont care i am a meanie beanie muhaahahaha
END
damn, another end huh
โ cat fileB
this is the
new content
in between the tags :)
โ ed -s fileA
# This is all typed in, you can save it in a file and do ed -s < edscript
# Add newlines after STARTs and before ENDs
g/START/s/START/START\
/
g/END/s/END/\
END/
# Delete everything between the first START and the next END
1;/START/+1;/END/-1d
# Read in the other file in between
-1r fileB
# Get rid of newlines after STARTs and before ENDs
g/START/.;+1j
g/END/-1;+1j
w
q
โ cat fileA
hello
world
how are you doing on this fine day
I am doing quite STARTthis is the
new content
in between the tags :)END
honestly i dont care i am a meanie beanie muhaahahaha
END
damn, another end huh
sed s/START/START\n/ (idk if that \n is correct)awk to filter out the unwanted content or perhaps split the file in pre-head and post-head parts, I'm not sure sed is able to store enough context to do it
s/^.*Forecast/\1/ (and the analog in awk).
sed uses the ancient POSIX Basic RE, you should always add -E to it on commandline to get a more modern looking regex (POSIX ERE / Extended Regular Expressions). Unless you use fancy stuff like backreferences, lookaheads, or such, basic regex knowledge from Perl/Python/Java/Javascript/anything-from-this-century should be transferrable to it