How to find out line-endings in a text file?
You can use the file
utility to give you an indication of the type of line endings.
Unix:
$ file testfile1.txttestfile.txt: ASCII text
"DOS":
$ file testfile2.txttestfile2.txt: ASCII text, with CRLF line terminators
To convert from "DOS" to Unix:
$ dos2unix testfile2.txt
To convert from Unix to "DOS":
$ unix2dos testfile1.txt
Converting an already converted file has no effect so it's safe to run blindly (i.e. without testing the format first) although the usual disclaimers apply, as always.
Ubuntu 14.04:
simple cat -e <filename>
works just fine.
This displays Unix line endings (\n
or LF) as $
and Windows line endings (\r\n
or CRLF) as ^M$
.
In vi
...
:set list
to see line-endings.
:set nolist
to go back to normal.
While I don't think you can see \n
or \r\n
in vi
, you can see which type of file it is (UNIX, DOS, etc.) to infer which line endings it has...
:set ff
Alternatively, from bash
you can use od -t c <filename>
or just od -c <filename>
to display the returns.