LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-01-2009, 03:01 PM   #1
nano2
Member
 
Registered: May 2007
Posts: 100

Rep: Reputation: 15
search and repalce a char in path using sed ???


Hi ,
I have the following path wher i want to replace forward slashes with back slashes using sed
path=/temp/file.tar

I am using the following but it's not working

any help or suggestion much appreciated ?
Thanks inadvance,

cat $path | sed -e 's//\/' > $path
 
Old 09-01-2009, 03:08 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Code:
$ _foo='/bar/baz/boo'
$ echo ${_foo} | sed 's/\//\\/g'
\bar\baz\boo
You just forgot to escape a couple things, and to replace all instances on the line.
 
Old 09-01-2009, 03:27 PM   #3
bbeers
Member
 
Registered: Jul 2002
Location: Florida
Distribution: Centos, Slackware
Posts: 260

Rep: Reputation: 30
Are you trying to modify the path to the file or the contents of the file?

If the former, use
Code:
 path2=$( echo $path | sed -e 's:\/:\\:g' )
if the latter, use
Code:
 sed -i -e 's:\/:\\:g' $path
HTH,

-Bob

Last edited by bbeers; 09-01-2009 at 03:37 PM. Reason: code blocks
 
Old 09-01-2009, 07:24 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
# path=/temp/file.tar
# echo ${path//\//\\}
\temp\file.tar
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you insert chars with sed when the char itself is '\'... trist007 Linux - Newbie 8 08-07-2009 05:41 PM
Global search and repalce in vi sph90457 Linux - Newbie 6 03-06-2008 11:31 AM
meta char and sed kaz2100 Programming 3 02-02-2007 02:57 PM
search in char array xxfunkxx Programming 2 12-12-2004 11:23 PM
How to Chnage Python's module search path (sys.path)? lramos85 Linux - Software 1 05-02-2004 06:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration