0

I am trying to replace a text with the help of sed but I am really puzzled about in finding the reason for failure.

    Main file
    ===========
    user@shell>cat test
    new=21:58:22
    old=09:58:22

    echo $new
    echo $old

    user@shell>sed -i 's/$old/$new/g' yoo
    user@shell>
    user@shell>
    desired output
    ==============
    user@shell>cat yoo
    09:58:22
    09:58:22
    09:58:2209:58:22
    09:58:2209:58:22
    asdasd
    user@shell>

After this I was assuming that I will get the new values in file yoo but no changes are reflection.

1 Answers1

0

You need to expand the variables using double quotes like this,

sed -i "s/$old/$new/g" yoo
Arnab Nandy
  • 6,472
  • 5
  • 44
  • 50