1

I am converting two text files to an array using readlines

f1 = File.open('current_routes.txt')
f2 = File.open('production_routes.txt')

file1lines = f1.readlines
file2lines = f2.readlines

puts file1lines.inspect
puts ''
puts file2lines.inspect

The two files are an exact copy and paste of each other:

["DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.\n", "Please register a mime type using `register_mime_type` then\n"]

["DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.\r\n", "Please register a mime type using `register_mime_type` then\r\n"]

Why does inspect on the first file add \n and inspection of the second file add \r\n?

I am trying to compare the files for differences and this is giving me trouble

Or maybe I should stick with golf.

2 Answers 2

2

Apparently the two files are not exact copies of each other but have different line endings. This may be a result of one file being an actual output from a linux server and the other resulting from a copy-and-paste in a Windows text editor.

Sign up to request clarification or add additional context in comments.

Comments

1

Guessing you're on a Windows machine and the copy is adding in \r. Try this:

file1lines = f1.readlines.map(&:chomp)
file2lines = f2.readlines.map(&:chomp)

String#chomp will remove either \n or \r\n. Then you can compare the rest of the string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.