User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 391,570 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,657 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 20275 | Replies: 2 | Solved
Reply
Join Date: Nov 2004
Posts: 8
Reputation: stharmon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
stharmon stharmon is offline Offline
Newbie Poster

replacing text with sed

  #1  
Mar 8th, 2005
Hi All,

I am sed and awk illiterate and needed some assistance. I would like to write a script that will have sed replace all spaces with \space.

For example.

Program Files would be... Program\ Files

I can figure out how to replace the space with a backslash, however, when I add a space in there it complains that it is not terminated. Does anyone out there know how to accomplish this?

Thanks in advance.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Location: Overflow State
Posts: 183
Reputation: Stack Overflow is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

Re: replacing text with sed

  #2  
Mar 8th, 2005
Hello,

If I understand correctly, you want to replace all space occurances to "\space" where space represents the space, ' ', character:
sed -i 's/ /\\ /' file
To clarify:
sed — Is the program.
-i — Is a sed option that can edit files in place (makes backup if extension supplied)
s/ / — Finds all occurances of space
\\ / — Replaces the space with '\ '. Without the single quotation marks.
file — Is the input file.

For reference, the s command is the substitution command. The / / statement is to find any occurance of a space. The \\ / statement will replace the space, ' ', found with '\ '.


- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.

IRC
Channel: irc.daniweb.com
Room: #c, #shell
Reply With Quote  
Join Date: Nov 2004
Posts: 8
Reputation: stharmon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
stharmon stharmon is offline Offline
Newbie Poster

Re: replacing text with sed

  #3  
Mar 9th, 2005
Woohoo! That is exactly what I was looking for. Thank you for taking the time to respond, as well as the clear explanation.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Shell Scripting Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 10:15 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC