How to find out line-endings in a text file?

前端 未结 11 1031
一向
一向 2020-11-28 00:15

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

11条回答
  •  暖寄归人
    2020-11-28 01:09

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

    Unix:

    $ file testfile1.txt
    testfile.txt: ASCII text
    

    "DOS":

    $ 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.

提交回复
热议问题