Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use sed to replace all backslashes with forward slashes

Tags:

bash

shell

sed

I want to be able to use sed to take an input such as:

C:\Windows\Folder\File.txt 

to

C:/Windows/Folder/File.txt 
like image 210
Emily Avatar asked Jul 28 '11 00:07

Emily


People also ask

How do I change backslash to forward slash in Linux?

Press \/ to change every backslash to a forward slash, in the current line. Press \\ to change every forward slash to a backslash, in the current line.

What is the difference between forward slashes and backslashes?

Summary: The Backslash and Forward SlashThe backslash (\) is mostly used in computing and isn't a punctuation mark. The forward slash (/) can be used in place of “or” in less formal writing. It's also used to write dates, fractions, abbreviations, and URLs.

How do you grep forward slash?

The forward slash is not a special character in grep, but may be in tools like sed, Ruby, or Perl. You probably want to escape your literal periods, though, and it does no harm to escape the slash. This should work in all cases: \.


1 Answers

sed can perform text transformations on input stream from a file or from a pipeline. Example:

echo 'C:\foo\bar.xml' | sed 's/\\/\//g' 

gets

C:/foo/bar.xml 
like image 161
Emiliano Poggi Avatar answered Sep 30 '22 16:09

Emiliano Poggi