Using a variable inside ‘sed’

I have declared a variable in a file. I want to set the value of this variable, to a variable in a different file. When I tried to use ‘sed’ to accomplish this, I encountered an error. The error was, its not getting the value from the old file and just places the variable name in the new file. By changing the command slightly, It works fine. Given below are the commands I used.





$ source OLD-FILE

$ sed -i ‘s/b=.*/b=\${a}/’ NEW-FILE    #Output : b=${a}  #Wrong

$ sed -i ‘s/b=.*/b=’$a/ NEW-FILE         #Output : b=one    #Correct One


5 thoughts on “Using a variable inside ‘sed’

மறுமொழியொன்றை இடுங்கள்

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  மாற்று )

Google+ photo

You are commenting using your Google+ account. Log Out /  மாற்று )

Twitter picture

You are commenting using your Twitter account. Log Out /  மாற்று )

Facebook photo

You are commenting using your Facebook account. Log Out /  மாற்று )


Connecting to %s