Post Made Community Wiki by don_crissti
1
source | link

Sure, you can do this with ed alone, no need for additional tools:

ed -s stuff_to_place.txt<<\IN
1,/# aliases/d
/# end aliases/,$d
,d
.r /home/username/.bashrc
/# aliases/x
.t.
.,/# end aliases/-d
,p
q
IN

if you're happy with the result, replace ,p with w /home/username/.bashrc to write the changes to ~/.bashrc (note the full path used with r and w; you can simply use .bashrc if it's in cwd).
How this works: we first delete the unneeded lines from stuff_to_place.txt. Then we delete the remaining ones (the aliases) with ,d. The text buffer is now empty while the cut buffer contains the lines we want. We then read the content of .bashrc into the text buffer, put the content of the cut buffer (x) to after the /# aliases/ line, duplicate the last line that was pasted (.t.) then delete from the duplicated line up to but not including /# end aliases/ and finally print or write changes and quit.