FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor


 
 
LinkBack Thread Tools
 
Old 03-04-2009, 04:20 PM
Steve Kemp
 
Default sed :(

On Wed Mar 04, 2009 at 18:14:54 +0100, josep wrote:
> why isn't it working?
>
> sed -i "s/#send host-name "andare.fugue.com";/send host-name $(cat
> /etc/hostname)/g" /etc/dhcp3/dhclient.conf

Because you've got nested quotes. e.g. This fails:

sed -i "s/"bob"/"chris"/g" /tmp/blah

You need to escape the quotes inside your search/replace section.

e.g to change "bob" to "chris" (including the quotes) you'd need:

sed -i "s/"bob"/"chris"/g" /tmp/blah

Steve
--
Managed Anti-Spam Service
http://mail-scanning.com/


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-04-2009, 10:04 PM
Emanoil Kotsev
 
Default sed :(

Tzafrir Cohen wrote:

> On Wed, Mar 04, 2009 at 06:21:18PM +0100, Johannes Wiedersich wrote:
>> josep wrote:
>> > why isn't it working?
>> >
>> > sed -i "s/#send host-name "andare.fugue.com";/send host-name $(cat
>> > /etc/hostname)/g" /etc/dhcp3/dhclient.conf
>>
>> your quotes don't match. (There are probably other issues as well.)
>
> They actually do. Perfectly.
>
> echo "hello "world" !"
>
> is the same as:
>
> echo "hello world !"
>
> Though the OP probably wanted:
>
> echo "hello "world" !"
>
> (As someone else in the thread already noted)
>

Oh, this is nonsense

we would then use echo to do the job of sed, wouldn't we?

regards


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-04-2009, 10:22 PM
Tzafrir Cohen
 
Default sed :(

On Thu, Mar 05, 2009 at 12:04:32AM +0100, Emanoil Kotsev wrote:
> Tzafrir Cohen wrote:
>
> > On Wed, Mar 04, 2009 at 06:21:18PM +0100, Johannes Wiedersich wrote:
> >> josep wrote:
> >> > why isn't it working?
> >> >
> >> > sed -i "s/#send host-name "andare.fugue.com";/send host-name $(cat
> >> > /etc/hostname)/g" /etc/dhcp3/dhclient.conf
> >>
> >> your quotes don't match. (There are probably other issues as well.)
> >
> > They actually do. Perfectly.
> >
> > echo "hello "world" !"
> >
> > is the same as:
> >
> > echo "hello world !"
> >
> > Though the OP probably wanted:
> >
> > echo "hello "world" !"
> >
> > (As someone else in the thread already noted)
> >
>
> Oh, this is nonsense
>
> we would then use echo to do the job of sed, wouldn't we?

Nither. We let $SHELL expand the command-line first.

But if you want a more complex example with sed:

sed -e "somano "with" a dog" /etc/passwd
sed -e "somano "with" a dog" /etc/passwd

--
Tzafrir Cohen | tzafrir@jabber.org | VIM is
http://tzafrir.org.il | | a Mutt's
tzafrir@cohens.org.il | | best
ICQ# 16849754 | | friend


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-04-2009, 10:28 PM
Emanoil Kotsev
 
Default sed :(

Tzafrir Cohen wrote:

>>
>> Oh, this is nonsense
>>
>> we would then use echo to do the job of sed, wouldn't we?
>
> Nither. We let $SHELL expand the command-line first.
>
> But if you want a more complex example with sed:
>
> sed -e "somano "with" a dog" /etc/passwd
> sed -e "somano "with" a dog" /etc/passwd
>

don't try to fool me on sed pls

sed -e "s:man: "with" a d:g" /etc/passwd
sed -e "s:man: "with" a d:g" /etc/passwd

is there any difference or is it more readable?

I meant you can not compare echo with sed

regards


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-04-2009, 10:45 PM
Tzafrir Cohen
 
Default sed :(

On Thu, Mar 05, 2009 at 12:28:45AM +0100, Emanoil Kotsev wrote:

> I meant you can not compare echo with sed

You're missing the point: it's not sed that expands things.

Run 'set -x' in your shell and run those examples. You'll see the
command after the expantion by the shell.

(Use 'set +x' to stop that noisy tracing)

--
Tzafrir Cohen | tzafrir@jabber.org | VIM is
http://tzafrir.org.il | | a Mutt's
tzafrir@cohens.org.il | | best
ICQ# 16849754 | | friend


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-05-2009, 07:34 AM
Chris Davies
 
Default sed :(

Steve Kemp <skx@debian.org> wrote:
> Because you've got nested quotes. e.g. This fails:
> sed -i "s/"bob"/"chris"/g" /tmp/blah

IMO that's a bad example, because it's not clear that the quotes
surrounding bob and chris are processed by the shell and therefore
never seen by sed. It "seems" to work even though you (correctly) say
it doesn't.

Chris


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-05-2009, 08:02 PM
Emanoil Kotsev
 
Default sed :(

Tzafrir Cohen wrote:

> On Thu, Mar 05, 2009 at 12:28:45AM +0100, Emanoil Kotsev wrote:
>
>> I meant you can not compare echo with sed
>
> You're missing the point: it's not sed that expands things.
>
> Run 'set -x' in your shell and run those examples. You'll see the
> command after the expantion by the shell.
>
> (Use 'set +x' to stop that noisy tracing)
>

so you don't want to escape the quotes?





--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 09:53 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org