Determine the new line character in a text file

text;

given a text, is there a program that can detect what the new line character is, the Windows, Mac, or Linux one?

Eg, the following text is shown by less

memor:^M^Mis storage directly accessible by CPU^M^MThe term "memory"
is often (but not always) associated with addressable semiconductor
memory, i.e. integrated circuits consisting of silicon-based
transistors.^MThe semiconductor memory i s organized into ^Mmemory
cells

I thought ^M is the new line character under Mac.
But in emacs, I searched by Ctrl-q Ctrl-m and found nothing.

Thanks.

Best Answer

file will report on line endings for text files. If you run file on an ASCII Unix/Linux/OSX text file, for example, it will report simply:

$ file test.txt
test.txt: ASCII text

If, however the file has DOS/Windows line-endings, it will instead report:

test.dos: ASCII text, with CRLF line terminators

Up to OS 9, Macs used CR as the line ending. When presented with such a file, file will report:

test.mac: ASCII text, with CR line terminators

With OSX, Macs converted to standard Unix line endings.

Related Question