Computing.Net > Forums > Linux > sed - how to append \ with /

sed - how to append \ with /

Reply to Message Icon

Original Message
Name: chitti
Date: September 20, 2007 at 03:01:35 Pacific
Subject: sed - how to append \ with /
OS: linux
CPU/Ram: 256
Model/Manufacturer: 2006
Comment:

Hi,
Please help me in resolving this problem.
I want to use sed command to change the path of file to have '\' along with '/'
for ex:-
echo "/usr/local/chitti/my_space" | sed -n "s/\//\\\//gp"

I get
\/usr\/local\/chitti\/my_space

But when same added in bash script I get the path as
/usr/local/chitti/my_space
Any help to resolve this will be greatly appreciated.

Thanks,
chitti.



Report Offensive Message For Removal


Response Number 1
Name: quacked
Date: September 21, 2007 at 17:32:07 Pacific
Reply: (edit)

This might better be answered in the programming forum,,,, I did a google search on using the sed command and with the way your using it ,, I'm a little unclear as to exactly what it is your trying to accomplish ,,, Perhaps

http://www.ncsa.uiuc.edu/UserInfo/R...

would be able to help somewhat,,,

MSI 845e mb 1 gb ram and a p4 2.4n running fedora 7 xp ,win 2000 advanced server and win 98 SE alot to learn and I know so little !!!!


Report Offensive Follow Up For Removal

Response Number 2
Name: Guy
Date: September 22, 2007 at 16:59:15 Pacific
Reply: (edit)

Do not use double quotes around the sed script, use single quotes like:

echo "/usr/local/chitti/my_space" | sed -n 's/\//\\\//gp'


Report Offensive Follow Up For Removal

Response Number 3
Name: quacked
Date: September 23, 2007 at 20:11:57 Pacific
Reply: (edit)

Syntax will get you every time,,,, Huh,,,!!!


Well Have Fun Huh!!!

MSI 845e mb 1 gb ram and a p4 2.4n running xp ,win 2000 advanced server and win 98 SE alot to learn and I know so little !!!!


Report Offensive Follow Up For Removal

Response Number 4
Name: chitti
Date: September 25, 2007 at 02:18:13 Pacific
Reply: (edit)

Thanks I found the other way - using awk
with FS as / and again concatenating all arguments with "\/" this when used in bash script worked perfectly.

Thanks,
Chitra


chitti


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: sed - how to append \ with /

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge