3

I run a program with two 'same' test files separately but got two different results.

First test file a.txt of 16 bytes leads to a right result, but second test file b.txt of 14 bytes causes the wrong result.

I saved both of them in encoding UTF-8.

Both of them consist of the following three lines when opened with Sublime Text in encoding UTF-8:

p cnf 1 1
1 0

However, they are different when opened with Sublime Text in encoding Hexadecimal:

a.txt (16 bytes):

7020 636e 6620 3120 310d 0a31 2030 0d0a

b.txt (14 bytes):

7020 636e 6620 3120 310a 3120 300a

Why they are different? How can I turn b.txt to a.txt?

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
sirius
  • 567
  • 6
  • 26
  • Note: some editors cleanup the file. Unicode text could have unnecessary code points (especially if input were a keyboard), and there are also different normalizations. In your case the accepted solution is the real reason, but you may encounter other cases. – Giacomo Catenazzi Mar 20 '19 at 14:24

1 Answers1

4

The first file has windows style end of line markers: a carriage return followed by a newline '\r\n', hex 0d 0a.

The second has unix style: a newline '\n' hex 0a.

There are many ways to convert from one style to the other. Sublime text may have an option to save with particular line endings, find/replace may work, or if you are on a Unix-like system you may try the answers to this question.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153