How to check whether lines in a text file end with CRLF or LF?
Asked
Active
Viewed 1.4k times
2
2 Answers
7
As Tom Hunt said, you can use file
and it will tell you if the lines end with CRLF.
Or you can use GNU cat -A filename
to visually inspect the file. Lines ending in CRLF will look like:
blahblahblah^M$
A more portable alternative is to use sed -n l filename
. Lines ending with CRLF will look like:
blahblahblah\r$

cas
- 78,579
0
I didn't know about the cat or sed ways, but I use this:
tr "\r" "@" < $FILE | grep --color "@$"
which replaces the CR with a @ (vim's ":set list" style) and shows the resulting @'s at the end of each line in color.

AlvaroGMJ
- 241
file <filename>
. If it makes no mention, it's LF; if it's CRLF, it'll say "with CRLF line terminators". – Tom Hunt Dec 01 '15 at 17:49LF
andCRLF
line endings? Please edit your question to clarify. – RobertL Dec 01 '15 at 20:27