Results 1 to 6 of 6
Hi,
I try to replace a string in a file like
a=text
b=4
c=5
I would like to replace with sed
$a:$b with $a:$c
I tried
Code:
sed 's/$a\:$b/$a\:$c/g' file.txt ...
- 03-12-2010 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 4
replace string with sed in bash
Hi,
I try to replace a string in a file like
a=text
b=4
c=5
I would like to replace with sed
$a:$b with $a:$c
I tried
Any ideas how to do it in a proper way.Code:sed 's/$a\:$b/$a\:$c/g' file.txt > file1.txt && mv file1.txt file.txt
Many thanks
- 03-12-2010 #2
you have to escape the $ too, since it has special meaning in a regexp (means the end of a string) so try:
Code:sed 's/\$a\:\$b/\$a\:\$c/g'
linux user # 503963
- 03-12-2010 #3Just Joined!
- Join Date
- Mar 2010
- Posts
- 4
Thanks,
That didn't changed it but I found it now
Code:sed "s/$a:$b/$a:$c/g"
- 03-12-2010 #4
are you sure you are using sed right? sed stands for Stream Editor, meaning it takes stuff from like stdout and such.
the data has to be incoming, so you will need to cat your files you want editted, and pipe them into set
so the output will be written into newfileCode:cat file1 | sed 's/\$a\:\$b/\$a\:\$c/g' > newfile; blah; blah etc
linux user # 503963
- 03-12-2010 #5Just Joined!
- Join Date
- Mar 2010
- Posts
- 4
thats true,
but thats how i did it
Code:sed "s/$a:$b/$a:$c/g" file1 > newfile && mv newfile file1
- 03-12-2010 #6
gnu sed knows -i, that is: inplace editing
So, no need for that tmp file and mv.
You must always face the curtain with a bow.


Reply With Quote