linux - I can't replace strings correctly with sed on terminal -
good day everyone, followed next find , replace within text file bash command.
now using sed solution seems work if utilize 2 predifined strings, want replace contents in file, , not defined me.
i have file words "kung fu dog" want replace word "dog" word "panda" word in file. tried doing:
sed -i 's/dog/$(cat filethatcontainspanda)/g' /home/myhome but problem instead of having word dog replaced panda, got word "dog" replaced "$(cat filethatcontainspanda)" in end instead of having "kung fu panda", have "kung fu $(cat filethatcontainspanda)". there workaround this?
you need utilize double quotes " instead of single ' , awk instead of cat:
sed -i "s/dog/$(awk '{print $1}' filethatcontainspanda)/g" /home/myhome linux bash sed scripting
No comments:
Post a Comment