我想在Linux上搜索包含带有grep的DOS行结尾的文件。如下所示:
grep -IUr --color '\r\n' .
上面的内容似乎与文字rn
相匹配,而这并不是我们所希望的。
它的输出将通过管道通过xargs转换为todos,以便将crlf转换为lf,如下所示
grep -IUrl --color '^M' . | xargs -ifile fromdos 'file'
发布于 2008-09-16 16:03:29
grep可能不是您想要的工具。它将为每个文件中的每个匹配行打印一行。除非您想在一个10行的文件上运行10次todos,否则grep不是最好的方法。使用find在树中的每个文件上运行file,然后浏览"CRLF“将为每个具有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
发布于 2012-11-30 18:20:28
使用RipGrep (根据您的shell,您可能需要引用最后一个参数):
rg -l \r
-l, --files-with-matches
Only print the paths with at least one match.
发布于 2010-07-06 15:53:28
# list files containing dos line endings (CRLF)
cr="$(printf "\r")" # alternative to ctrl-V ctrl-M
grep -Ilsr "${cr}$" .
grep -Ilsr $'\r$' . # yet another & even shorter alternative
https://stackoverflow.com/questions/73833
复制相似问题