题
我想检查任何特定目录中是否存在任何DOS文件。有什么方法可以将DOS文件与unix与 ^m chars区分开?
我尝试使用文件,但两者都给出了相同的输出。
$ file test_file
test_file: ascii text
转换后:
$ unix2dos test_file test_file
$ file test_file.txt
test_file.txt: ascii text
解决方案
CRLF(\r\n
, ^M
)线路结尾是unix和dos/windows ascii文件之间的唯一区别,所以没有其他方法。
如果您必须尝试什么 fromdos
命令是将其输出与原始文件进行比较:
file=test_file
fromdos < $file | cmp $file -
这失败了(非零 $?
) 如果 fromdos
剥去了任何 \r
离开。
dos2unix
可能以类似的方式使用,但我不知道它的确切语法。
其他提示
如果您实际上将Windows Newlines放入其中,您会看到以下输出 file
:
test_file.txt: ASCII text, with CRLF line terminators
不隶属于 StackOverflow