Computing.Net > Forums > Unix > sed problem with regular expression

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

sed problem with regular expression

Reply to Message Icon

Original Message
Name: elpico
Date: April 26, 2005 at 06:32:23 Pacific
Subject: sed problem with regular expression
OS: Solaris
CPU/Ram: ?
Comment:

Hi all,

I'm having a problem with a script I am using. I need to pass in a directory as a dynamic varible, but this directory needs to get added to lots of different files. So, I'm using sed to change the string from eg, /export/home/walsh to \/export\/home\/walsh - otherwise it doesn't get updated correctly.

The script I'm usiong works on the command prompt:

my_dir=/export/home/walshk
echo $my_dir | sed 's/\//\\\//g'

But when I run it from within my ksh script I get the garbled message...any ideas where I'm going wrong with this?

Thanks,
e.


Report Offensive Message For Removal


Response Number 1
Name: David Perry
Date: April 26, 2005 at 07:27:45 Pacific
Reply: (edit)

Pick a delimeter other than "/" if you plan to work with paths.

echo $my_dir | sed 's,/,\/,g'


Report Offensive Follow Up For Removal

Response Number 2
Name: elpico
Date: April 26, 2005 at 07:38:54 Pacific
Reply: (edit)

THanks for that - I got it working when I changed the seperators to pipes instead - sed 's|\/|\\\/|g'

Cheers,
k.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home








Do you have a Desktop Computer anymore?

No
Yes, but only at work
Yes, but its rarely used
Yes, and its a workhorse


View Results

Poll Finishes Today.
Discuss in The Lounge
Poll History




Data Recovery Software