Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find files with at least one CR LF

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?

like image 775
blueFast Avatar asked Oct 12 '15 14:10

blueFast


People also ask

How can I tell if a file is CRLF or LF?

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.

What is Windows CR LF?

(Carriage Return/Line Feed) Two characters that indicate the end-of-line (end-of-paragraph) in Windows and DOS. See line break.

Where is CR LF in Unix?

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.

How do I show CR LF in Notepad ++?

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.


1 Answers

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).

like image 75
anubhava Avatar answered Sep 21 '22 21:09

anubhava