Say I had a block of text in the
#~/.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... # aliases alias ldir='ls * -d' alias ithinklifeisworthliving='echo all good' # end aliases # ...more stuff...
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
How do I replace the other section in
~/.bashrcwith the extracted text from question 1?
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.