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
nospam [ Di, 06 September 2005 10:29 ] [ ID #953760 ]

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>
cfajohnson [ Di, 06 September 2005 10:58 ] [ ID #953762 ]

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
nospam [ Di, 06 September 2005 11:42 ] [ ID #953765 ]

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
Christophe Gaubert [ Di, 06 September 2005 13:58 ] [ ID #953776 ]

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>
cfajohnson [ Di, 06 September 2005 15:11 ] [ ID #953778 ]

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
Christophe Gaubert [ Di, 06 September 2005 15:26 ] [ ID #953779 ]
Linux » comp.unix.shell » sed: looking for a string and replace a line (newbies question)

Vorheriges Thema: how to exclude file and folder from while taring in solaris 8?
Nächstes Thema: dumb question