Skip to content

Instantly share code, notes, and snippets.

@keldin-coding
Created June 20, 2019 04:54
Show Gist options
  • Save keldin-coding/716a8e06214579e859b576f81cffa94e to your computer and use it in GitHub Desktop.
Save keldin-coding/716a8e06214579e859b576f81cffa94e to your computer and use it in GitHub Desktop.
Escape backslashes in text
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
@keldin-coding
Copy link
Author

Edit this code with ./foo.txt to be your text file
Make ./foo_formatted.text whatever you want to write the file to

ruby ./replaceslash.rb 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment