Hi,
i have a file with lines,
file.txt
-------
test is fun
testing is better
I need to replace 'test' to 'develop' and i used,
a=test
b=develop
sed "s,$a,$b,g" -------- but i see the word 'testing' is also replaced. Need some solution. Is there any way i could replace only 'test' ?
use a space after test like
a="test "
b="develop "
One idea - put space at front and back of each line, then replace <space>test<space> with <space>develop<space> then take spaces off front and back:
$ a=test
$ b=develop
$ echo "test and testing and test" | sed "s/^/ /;s/\$/ /;s/ $a / $b /g;s/^ //;s/ $//"
develop and testing and develop
But, I'm sure someone will come up with a better way but.
Hi,
Please try this.
cat file.txt | sed 's:$a:$b:g'
giri_luck:
Hi,
i have a file with lines,
file.txt
-------
test is fun
testing is better
I need to replace 'test' to 'develop' and i used,
a=test
b=develop
sed "s,$a,$b,g" -------- but i see the word 'testing' is also replaced. Need some solution. Is there any way i could replace only 'test' ?
Leave a space after $a in the sed command
sed "s,$a ,$b ,g" file.txt > outfile