In a bash script, files with spaces show up as "File\ with\ spaces.txt" and I want to substitute those slashed-spaces with either _ or +.
How can I tell sed to do that? I had no success using;
$1=~/File\ with\ spaces.txt
ext=$1
web=$(echo "$ext" | sed 's/\ /+/')
I’m open to suggestions if there’s a better way than through sed.
[EDIT]: Foo Bah’s solution works well, but it substitutes only the first space because the text following it is treated as arguments rather than part of the $1. Any way around this?
Sed recognises
\as space just fine:Your bash script syntax is all wrong, though.
Not sure what you were trying to do with the script, but here is an example of replacing spaces with
+:Upd:
Oh, and you need the
gflag to replace all occurences of space, not only the first one. Fixed above.