Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the line ending of a file

I have a bunch (hundreds) of files that are supposed to have Unix line endings. I strongly suspect that some of them have Windows line endings, and I want to programmatically figure out which ones do.

I know I can just run

flip -u
or something similar in a script to convert everything, but I want to be able to identify those files that need changing first.
like image 634
nwahmaet Avatar asked Sep 23 '08 14:09

nwahmaet


People also ask

How do I know if a file is LF or CR 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 end of line in text file?

Windows programs normally use a carriage return followed by a line feed character at the end of each line of a text file. In ASCII, carriage return/line feed is X'0D'/X'0A'.

What does line ending mean?

Line endings also called newline, end of line (EOL) or line break is a control character or sequence of control characters in a character encoding specification (e.g. ASCII or EBCDIC) that is used to signify the end of a line of text and the start of a new one.

How do I get the lines of a file?

The wc -l command is the most used, and also the easiest way to find the line numbers of a given file.


1 Answers

You can use the file tool, which will tell you the type of line ending. Or, you could just use dos2unix -U which will convert everything to Unix line endings, regardless of what it started with.

like image 105
Adam Rosenfield Avatar answered Sep 26 '22 07:09

Adam Rosenfield