Marco Ceppi Marco Ceppi - 11 months ago 61
Linux Question

View line-endings in a text file

I'm trying to use something in bash to show me the line endings in a file printed rather than interpreted. The file is a dump from SSIS/SQL Server being read in by a Linux machine for processing.

Is there any switches within

, etc?

In addition to seeing the line-endings, I need to know what type of line end it is (CRLF or LF).

Answer Source

You can use the file utility to give you an indication of the type of line endings.


$ file testfile1.txt
testfile.txt: ASCII text


$ file testfile2.txt
testfile2.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.