Created
June 20, 2019 04:54
-
-
Save keldin-coding/716a8e06214579e859b576f81cffa94e to your computer and use it in GitHub Desktop.
Escape backslashes in text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lines = File.readlines('./foo.txt', 'r') | |
File.open('./foo_formatted.txt', 'w') do |f| | |
lines.each do |line| | |
newline = line.gsub("\\", "\\\\\\\\") | |
f << newline | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edit this code with
./foo.txt
to be your text fileMake
./foo_formatted.text
whatever you want to write the file to