sed: looking for a string and replace a line (newbies question)
Hi,
I have this file: ./kav4sambaservers.conf
[updater.options]
UseProxy=no
ProxyAddress=http://myURL:8080
I want replace the LINE of "UseProxy=something"
(the same for the line ProxyAddress=http://myURL:8080)
I use:
#sed -e 's/^*UseProxy=*$/^UseProxy=yes$/g' ./kav4sambaservers.conf >
../test.conf
I want replace the line with "UseProxy=" string by another line...
but my command doesn't work because I'm a beginner in this scripts...
Thxs
--
Sorry to use Google but now I'm on work with a nice proxy/firewall
without NNT
Re: sed: looking for a string and replace a line (newbies question)
On 2005-09-06, NoSpam wrote:
> Hi,
> I have this file: ./kav4sambaservers.conf
> [updater.options]
> UseProxy=no
> ProxyAddress=http://myURL:8080
>
> I want replace the LINE of "UseProxy=something"
> (the same for the line ProxyAddress=http://myURL:8080)
>
> I use:
> #sed -e 's/^*UseProxy=*$/^UseProxy=yes$/g' ./kav4sambaservers.conf >
> ./test.conf
> I want replace the line with "UseProxy=" string by another line...
> but my command doesn't work because I'm a beginner in this scripts...
Use a regular expression, not a file globbing pattern.
sed -e 's/^*UseProxy=.*/UseProxy=yes/' ./kav4sambaservers.conf >> ./test.conf
To match any number of any characters, use ".*", not "*".
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
============================================================ ======
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>
Re: sed: looking for a string and replace a line (newbies question)
Thxs u help me:
sed -e 's/^.*UseProxy=.*/UseProxy=Ho YES/' ./kav4sambaservers.conf >
../test.conf
mv -f ./test.conf ./kav4sambaservers.conf
Re: sed: looking for a string and replace a line (newbies question)
NoSpam a écrit :
> sed -e 's/^.*UseProxy=.*/UseProxy=Ho YES/' ./kav4sambaservers.conf >
> ./test.conf
>
> mv -f ./test.conf ./kav4sambaservers.conf
>
You can also use the -i option of sed to avoid the use of a temporary file :
sed -i -e 's/^.*UseProxy=.*/UseProxy=Ho YES/' ./kav4sambaservers.conf
--
Christophe Gaubert
http://perso.wanadoo.fr/christophe.gaubert
Mail posté depuis un système libre GNU/Linux
Re: sed: looking for a string and replace a line (newbies question)
On 2005-09-06, Christophe Gaubert wrote:
> NoSpam a écrit :
>> sed -e 's/^.*UseProxy=.*/UseProxy=Ho YES/' ./kav4sambaservers.conf >
>> ./test.conf
>>
>> mv -f ./test.conf ./kav4sambaservers.conf
>>
>
> You can also use the -i option of sed to avoid the use of a temporary file :
> sed -i -e 's/^.*UseProxy=.*/UseProxy=Ho YES/' ./kav4sambaservers.conf
Only if you are using GNU sed; -i is not a standard option.
Besides, it is safer not to edit the file _in situ_, especially if
a person has to ask how to do it.
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
============================================================ ======
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>
Re: sed: looking for a string and replace a line (newbies question)
Chris F.A. Johnson a écrit :
> Only if you are using GNU sed; -i is not a standard option.
I didn't knew it. Thanks.
--
Christophe Gaubert
http://perso.wanadoo.fr/christophe.gaubert
Mail posté depuis un système libre GNU/Linux