How to find a windows end of line (EOL) character How to find a windows end of line (EOL) character unix unix

How to find a windows end of line (EOL) character


The file(1) utility knows the difference:

$ file * | grep ASCII2:                                       ASCII text3:                                       ASCII English texta:                                       ASCII C program textblah:                                    ASCII Java program textfoo.js:                                  ASCII C++ program textopenssh_5.5p1-4ubuntu5.dsc:              ASCII text, with very long lineswindows:                                 ASCII text, with CRLF line terminators

file(1) has been optimized to try to read as little of a file as possible, so you may be lucky and drastically reduce the amount of disk IO you need to perform when finding and fixing the CRLF terminators.

Note that some cases of CRLF should stay in place: captures of SMTP will use CRLF. But that's up to you. :)


#!/bin/bashfor i in $(find . -type f); do        if file $i | grep CRLF ; then                echo $i                file $i                #dos2unix "$i"        fidone

Uncomment "#dos2unix "$i"" when you are ready to convert them.


You can find out using file:

file /mnt/c/BOOT.INI /mnt/c/BOOT.INI: ASCII text, with CRLF line terminators

CRLF is the significant value here.