的DOS2UNIX的(和unix2dos)命令與Cygwin和最近的一些Linux發行版安裝的最新版本(7.1)版有一個方便的--info選項,打印出每個文件中不同類型的換行符的數量。這是DOS2UNIX的7.1(2014年10月6日)http://waterlan.home.xs4all.nl/dos2unix.html
從手冊頁:
--info[=FLAGS] FILE ...
Display file information. No conversion is done.
The following information is printed, in this order:
number of DOS line breaks, number of Unix line breaks, number of Mac line breaks, byte order mark, text or binary, file name.
Example output:
6 0 0 no_bom text dos.txt
0 6 0 no_bom text unix.txt
0 0 6 no_bom text mac.txt
6 6 6 no_bom text mixed.txt
50 0 0 UTF-16LE text utf16le.txt
0 50 0 no_bom text utf8unix.txt
50 0 0 UTF-8 text utf8dos.txt
2 418 219 no_bom binary dos2unix.exe
Optionally extra flags can be set to change the output. One or more flags can be added.
d Print number of DOS line breaks.
u Print number of Unix line breaks.
m Print number of Mac line breaks.
b Print the byte order mark.
t Print if file is text or binary.
c Print only the files that would be converted.
With the "c" flag dos2unix will print only the files that contain DOS line breaks, unix2dos will print only file names that have Unix line breaks.
這樣:
if [[ -n $(dos2unix --info=c "${filename}") ]] ; then echo DOS; fi
相反:
if [[ -n $(unix2dos --info=c "${filename}") ]] ; then echo UNIX; fi
然而,我的AIX機器中的ksh只告訴我'test.txt:ascii text',不管在'test.txt'中使用了哪種類型的行尾。它不告訴我是否包含CRLF。 –