Page 1 of 1

sed Question (FAQs answer doesn't work!)(Solved)

Posted: Sun 14 Aug 2005, 12:21
by ozboomer
This is sending me silly...

Using puppy v1.0.1 or v1.0.4...

# tmpdir=/tmp/root
# echo /root/etc/hosts | sed 's/root/abc/'

...gives /abc/etc/hosts

# echo /root/etc/hosts | sed 's/root/$tmpdir/'

...gives /$tmpdir/etc/hosts

# echo /root/etc/hosts | sed "s/root/$tmpdir/"

...gives "sed: -e expression #1, char 9: Unknown option to 's'"

The sed FAQs suggest the variable substitution happens when the double-quotes are used... but all I get is the syntax error.

Gnu sed v4.0.7 is included in both Puppy v1.0.1 and v1.0.4.

What do I have to do to get the variable substitution to work!?


John

Posted: Sun 14 Aug 2005, 13:18
by Guest
tmpdir=/tmp/root
echo /root/etc/hosts | sed "s%/root%$tmpdir%"

Posted: Sun 14 Aug 2005, 13:35
by ozboomer
Anonymous wrote:tmpdir=/tmp/root
echo /root/etc/hosts | sed "s%/root%$tmpdir%"
Great. Many thanks. Forgot all about the other delimiters :)

Posted: Sun 14 Aug 2005, 13:47
by Guest
got beaten to the punch

Posted: Mon 15 Aug 2005, 00:00
by Flash
Bladehunter: isn't it worth answering all those easy questions to find one like this one? :)