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?
use a text editor like notepad++ that can help you with understanding the line ends. It will show you the line end formats used as either Unix(LF) or Macintosh(CR) or Windows(CR LF) on the task bar of the tool. you can also go to View->Show Symbol->Show End Of Line to display the line ends as LF/ CR LF/CR.
(Carriage Return/Line Feed) Two characters that indicate the end-of-line (end-of-paragraph) in Windows and DOS. See line break.
Try file -k It will output with CRLF line endings for DOS/Windows line endings. It will output with CR line endings for MAC line endings. It will just output text for Linux/Unix "LF" line endings.
In Notepad++ go to the View > Show Symbol menu and select Show End of Line. Once you select View > Show Symbol > Show End of Line you can see the CR LF characters visually.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With