Say I had a block of text in the ~/.bashrc
:
#~/.bashrc
# ...some commands...
# aliases
alias suicide='sudo rm -rf /'
# end aliases
# other commands
I wish to replace that block of text with some other text contained between two markers in another file: stuff-to-place-in-bashrc.txt
# stuff-to-place-in-bashrc.txt
# ...stuff...
# aliases
alias ldir='ls * -d'
alias ithinklifeisworthliving='echo all good'
# end aliases
# ...more stuff...
I've tried
sed -ne 's/# aliases\s+\(.*\)\s+# end aliases/\1/' stuff-to-place-in-bashrc.txt
But I'm really swinging in the dark here. Could someone help me out?
How do I extract the text from the
stuff-to-place-in-bashrc.txt
?How do I replace the other section in
~/.bashrc
with the extracted text from question 1?
Edit
Thanks for the updates guys, those wondering why i would want something like this:
allows for cherry-picked updates to script files without overwritting user-made additions. useful for shared and frequently updated standard operating environments (like my last job at Tyro that coded with XP).
go crazy guys.
# aliases
and# end aliases
), and it may work for you. – May 09 '16 at 04:41