Skip to content Skip to sidebar Skip to footer

^m Characters In Exported File, Converting To Newlines

I exported a CSV from excel to parse using python. When I opened the vimmed the CSV, I noticed that it was all one line with ^M characters where newlines should be. Name, Value, Va

Solution 1:

^M is how vim displays windows end-of-line's

The dos2unix command should fix those up for you:

dos2unix my_file.csv

It's due to the different EOL formats on Windows/Unix.

On windows, it's \r\n

On Unix/Linux/Mac, it's just \n

The ^M is actually vim showing you the windows CR (Carriage Return) or \r

The python open command documentation has more information on handling Universal Newlines: http://docs.python.org/2/library/functions.html#open

Solution 2:

If you are on a unix system, there is a program called dos2unix (and its counterpart unix2dos) that will do exactly that conversion.

But, it is pretty much the same as something like this:

sed -i -e 's/$/\r/' file

Post a Comment for "^m Characters In Exported File, Converting To Newlines"