I would like to use sed to convert a path with backslashes to the same path with forward slashes:
E.g.
I would like to pipe \\path\to\file\ and obtain /path/to/file
None of the following commands work, and I can't tell why:
First attempt:
> echo '\\path\to\file\' | sed 's/\\/\//g'
/path o
ile/
Second attempt:
echo \\path\to\file\ | sed 's/\\/\//g'
/pathtofile
Third attempt:
echo "\\path\to\file\" | sed 's/\\/\//g'
dbquote>
I get a similar behavior if I try piping to | tr '\' '/'
I am looking for the correct answer and, if possible, for an explanation of why none of the attempts above worked. Not sure if it matters, but this is all on zsh 4.2.6 (x86_64-redhat-linux-gnu)
Thanks!


echo '\\path\to\file\' | sed -r 's:\\+:/:g'. – Thor Sep 11 '12 at 14:23zshare you using? – Thor Sep 11 '12 at 14:24