linux - 如何在 Linux 上使用 grep 搜索包含 DOS 行尾 (CRLF) 的文件?

我想在 Linux 上使用 grep 搜索包含 DOS 行结尾的文件。像这样的:

grep -IUr --color '\r\n' .

上面的内容似乎与文字 rn 匹配,这不是我们想要的。

this 的输出将通过 xargs 传递到 todos 中,像这样将 crlf 转换为 lf

grep -IUrl --color '^M' . | xargs -ifile fromdos 'file'

最佳答案

grep 可能不是您想要的工具。它将为每个文件中的每个匹配行打印一行。除非你想在一个 10 行的文件上运行 10 次 todos,否则 grep 并不是最好的方法。使用 find 在树中的每个文件上运行文件,然后对“CRLF”进行 grepping,将为每个具有 dos 样式行结尾的文件提供一行输出:

find . -not -type d -exec file "{}" ";" | grep CRLF

会给你类似的东西:

./1/dos1.txt: ASCII text, with CRLF line terminators
./2/dos2.txt: ASCII text, with CRLF line terminators
./dos.txt: ASCII text, with CRLF line terminators

https://stackoverflow.com/questions/73833/

相关文章:

linux - 如何列出(ls)目录中最后修改的 5 个文件?

linux - Apache VirtualHost 403 被禁止

python - "for line in..."导致 UnicodeDecodeError : '

python - Python中的异步方法调用?

linux - 在 tmux 客户端之间移动窗口

linux - 如何查看符号链接(symbolic link)的完整绝对路径

linux - 如何找到某个命令的目录?

python - 计算列表差异

python - 如何将字符串复制到剪贴板?

linux - 如何在 Linux shell 中对变量进行除法?