我想在 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/