PDA

View Full Version : [SOLVED] Need a sed or awk one-liner



DGortze380
June 3rd, 2010, 02:16 PM
I can't seem to find the right syntax for this.

Using Bash with sed and/or awk I need to replace all spaces in a string with a backslash and a space.

EX.

Name With Spaces
Name\ With\ Spaces

Any help would be appreciated.

DaithiF
June 3rd, 2010, 02:33 PM
Hi,


$ echo "Name With Spaces" | sed 's/ /\\ /g'
Name\ With\ Spaces

DaithiF
June 3rd, 2010, 02:36 PM
or just using bash:

$ in="Names With Spaces"
$ echo ${in// /\\ }
Names\ With\ Spaces

DGortze380
June 3rd, 2010, 02:51 PM
Awesome!

Thanks.