Reputation: 44381
I am on Linux. I have received a mixed list of files, which I have forgotten to verify beforehand. My editor (emacs) has used LF (\n
) for some files which originally had CR+LF (\r\n
) (!!). I have realized about this way too late, and I think this is causing me trouble.
I would like to find all files in my cwd which have at least one CR+LF in them. I do not trust the file
command, because I think it only checks the first lines, and not the whole file.
I would like to check whole files to look for CR + LF. Is there a tool for that, or do I need to roll my own?
Upvotes: 5
Views: 2562
Reputation: 1124
dos2unix can not only convert dos line ends (CR+LF) to unis (LF) but also display file information with a -i option. e.g.
sh-4.3$ (echo "1" ; echo "") > 123.txt
sh-4.3$ unix2dos 123.txt
unix2dos: converting file 123.txt to DOS format...
sh-4.3$ cat 123.txt ; hexdump -C 123.txt ; dos2unix --info='du' 123.txt
1
00000000 31 0d 0a 0d 0a |1....|
00000005
2 0 123.txt
sh-4.3$ dos2unix 123.txt
dos2unix: converting file 123.txt to Unix format...
sh-4.3$ cat 123.txt ; hexdump -C 123.txt ; dos2unix --info='du' 123.txt
1
00000000 31 0a 0a |1..|
00000003
0 2 123.txt
Upvotes: 0
Reputation: 785276
You can use this grep
command to list all the files in a directory with at least one CR-LF
:
grep -l $'\r$' *
Pattern $'\r$'
will file \r
just before end of each line.
Or using hex value:
grep -l $'\x0D$' *
Where \x0D
will find \r
(ASCII: 13).
Upvotes: 6