1

i need a quick command (linux or windows) to replace every \\ with a /, and all tries with sed failed because of the /. (I already tried find . -name '*.*' -exec sed -i 's/\\///g' {} \;, but i think it failed with the "/".

tripleee
  • 175,061
  • 34
  • 275
  • 318

1 Answers1

1
find . -name '*.*' -type f -exec sed -i 's:\\\\:/:g' {} \;

You need to escape each backslash, and using a colon or comma as separators is generally recommended when making replacements with forward-slash. However, escaping the forward slash works too:

find . -name '*.*' -type f -exec sed -i 's/\\\\/\//g' {} \;

As pointed out in comments the OS module is probably what you really need to look at.

Edit: thanks to @tripleee for reminding me of the -type f line, which limits it to files, rather than including the current directory.

Also, I copied the syntax *.* from the OP but in general it isn't helpful. * alone is usually what you want, since files aren't guaranteed to have a dot in their name. Assuming you were happy to include files not containing a dot, the simplest thing to do here is have no -name at all:

find . -type f -exec sed -i 's:\\\\:/:g' {} \;
GKFX
  • 1,386
  • 1
  • 11
  • 30