SED with variable that contains spaces?
Im having problems using SED to replace with a variable. I assume the problem is that the variable contains spaces.
Code:
data=$(grep 'DATA' vsm.scr) DATA /home/temp/abc.txt (There are additional spaces in front of DATA, they dont show up in the forum post) Ive tried setting the variable as a simple number and everyhting works fine, which leads me to believe its a problem with the spaces Any ideas? |
Please provide an example of the line being replaced? As it stands i am unable to reproduce a problem.
|
sed "s/loc/$data/g" v1.scr > v2.scr
loc is being replaced and is not a variable. $data has the following format: Code:
DATA /home/temp/abc.txt |
The problematic characters are not the spaces, since you correctly used double quotes to embed the sed command, but the slashes. They interfere with the separator used in the s command. To avoid this unwanted behaviour, use another character as separator, e.g.
Code:
sed "s:loc:$data:g" v1.scr > v2.scr |
Quote:
|
All times are GMT -5. The time now is 10:25 PM. |