CRLF/LF line endings, and how to change them.
Windows text files tend to have carriage-return line-feed characters at the end of each line. CRLF.
Linux text files have a line-feed character at the end of the line. LF.
In linux, a quick way of seeing the format of text files is the 'file' command. e.g.
my_file.csv: ASCII text, with CRLF line terminators <-- This is bad!
my_file.csv: ASCII text <-- This is good!
If you want to view the file and see the nasty CR character, then do this;
some_field,another_field,last_one^M
See that ^M ? Well, that's the CR character. If you're parsing the CSV file in linux, that last field will be read as 'last_one^M'
How to fix it? - Open the file in an editor capable of handling line-endings correctly, and save it. Notepad++ does this, as does vim, emacs, geaney, eclipse, gedit and most good text editors. But don't use Windows Notepad!
To convert line endings from CRLF to LF in vim, do this:
:update Save any changes.
:e ++ff=dos Edit file again, using dos file format ('fileformats' is ignored).[A 1]
:setlocal ff=unix This buffer will use LF-only line endings when written.[A 2]
:w Write buffer using unix (LF-only) line endings.
Borrowed from: http://vim.wikia.com/wiki/File_format#Converting_the_current_file