Guys,
I've a problem in the "sed" command used in my shellscripts
This is the problamatic line in my shell script:
sed -e 's/${line1}/${line1_m}/g' prod_hier_1234.txt > test.txt
It doesn't do the job of replacing the string stored in variable 'line1' to 'line1_m'.
However If I replace the line as below(by replacing the actual string)
sed -e 's/A,P,CMD,20-SEP-06,2006/A,P,CMD,20-SEP-06,20062814/g' prod_hier_1234.txt>test.txt
it works..
Could someone provide thougs about what could be the problem and the possible solution?
I haven't tested it but don'y you have to double quote your sed scripting instead of single when using variables?
sed -e "s/${line1}/${line1_m}/g" prod_hier_1234.txt > test.txt
If line1 contains special chars for sed like [ . *, they must be preceded by \ to loose they special meaning.
For example if you want to replace the string 'Bye.', line1 must contains 'Bye\.'
In the same way the replacement string can contains special char or expression like & \1. Using \ may bee need.
For example to replace string 'You' by 'You & Me', line1_m must contains 'You \& Me'.