I want to search for files containing DOS line endings with grep on Linux. Something like this:
grep -IUr --color \'\\
The query was search... I have a similar issue... somebody submitted mixed line
endings into the version control, so now we have a bunch of files with 0x0d
0x0d
0x0a
line endings. Note that
grep -P '\x0d\x0a'
finds all lines, whereas
grep -P '\x0d\x0d\x0a'
and
grep -P '\x0d\x0d'
finds no lines so there may be something "else" going on inside grep when it comes to line ending patterns... unfortunately for me!
If your version of grep supports -P (--perl-regexp) option, then
grep -lUP '\r$'
could be used.
dos2unix
has a file information option which can be used to show the files that would be converted:
dos2unix -ic /path/to/file
To do that recursively you can use bash
’s globstar
option, which for the current shell is enabled with shopt -s globstar
:
dos2unix -ic ** # all files recursively
dos2unix -ic **/file # files called “file” recursively
Alternatively you can use find
for that:
find -exec dos2unix -ic {} + # all files recursively
find -name file -exec dos2unix -ic {} + # files called “file” recursively