•
•
•
•
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
![]() |
•
•
Join Date: Nov 2004
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
•
•
Join Date: Sep 2004
Location: Overflow State
Posts: 183
Reputation:
Rep Power: 4
Solved Threads: 4
Hello,
If I understand correctly, you want to replace all space occurances to "\space" where space represents the space, ' ', character:
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
If I understand correctly, you want to replace all space occurances to "\space" where space represents the space, ' ', character:
sed -i 's/ /\\ /' file
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
IRC
Channel: irc.daniweb.com
Room: #c, #shell
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
- Replacing text (Shell Scripting)
- Replacing a large amount of text (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: Shell Script Help
- Next Thread: Help "sell script to send a mail"


Linear Mode