I have a file that contains string in each line. I used this file as an input in a program that reads them automatically. The program seem to not be able to read the strings correctly. I tried to fiure out what is different than usual. The only thing I found is that the file (I take it as-is from a source) adds the newline character at the beginning of the new line, and not at the end of the previous line as I used to see and as the program could successfully read previous files.
So if I use cat -E file.txt
to see the newline character I see the file contains string like this:
string1
$string2
$string3
$string4
Note that the $
is the newline character.
As a troubleshooting step, I want to change the newline position to be:
string1$
string2$
string3$
string4$
How to do this?
\r\n
newlines? – Kusalananda Apr 12 '19 at 13:34cat -E
is what I put in the OP. – user9371654 Apr 12 '19 at 13:38dos2unix filename
to change the file's newlines from DOS to Unix. This is very likely your issue. I have tested it to verify thatcat -E
produce this kind of output for DOS text files. – Kusalananda Apr 12 '19 at 13:41file
command, if tell you if it's plain ASCII or ASCII with DOS line endings. – xenoid Apr 12 '19 at 13:41$
in the output fromcat -E
. – Kusalananda Apr 12 '19 at 13:45file
command:ASCII text, with CRLF line terminators
– user9371654 Apr 12 '19 at 13:49CRLF
is "carriage return followed by line feed", i.e. a DOS text file. – Kusalananda Apr 12 '19 at 13:51