Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a plain text file of tab-separated values that was created on a Windows machine. I want to import it into Mathematica on a Mac.

rawdata = Import["filename.csv", "tsv"]

The output list has a blank list every other element. I think this is due to the old \r\n-vs-\n compatibility issue. How can I tell Import which convention the input file is using?

Edit: I should mention that I want to do this in a cross-platform way, because I'll probably be moving notebooks between Mac and Windows machines. So simply skipping every other element of the output list ([[1;2;-1]]) won't work.

Edit 2: This is what the file looks like when I open it in Emacs:

...
4.510000000000000E+008  -1.052316667849458E+002 -1.412043034275902E+002 ^M
4.515000000000000E+008  -1.159523802353636E+002 1.631532615796773E+002 ^M
...

The spaces between the fields are tabs. A moment's Googling tells me that ^M is a carriage return (\r). This fits my hypothesis that the Windows-based device is terminating lines with \r\n, and Mathematica is reading that as two new-lines. My question remains: How do I tell Import what EOL characters are in use in my file?

share|improve this question
Why the file name extension is .csv while the format of the file is TSV? The Import must not depend on this but it is strange. Which Mathematica version are you using? – Alexey Popkov Jan 16 at 17:37
@belisarius I did. @AlexeyPopkov it was generated by a scientific instrument, and that's the format it came in. csv files are just plain text anyway. – poorsod Jan 16 at 22:31
@poorsod - check the HEX of the end-of-line with an editor like Vim. Regular CSV end-of-line should be OdOa (as in CR/LF or \r\n). Perhaps you have something else. – Chris Degnen Jan 17 at 9:25
@ChrisDegnen, please see my edit. – poorsod Jan 17 at 17:46

migrated from stackoverflow.com Jan 17 at 16:48

1 Answer

up vote 3 down vote accepted

It looks like that "IgnoreEmptyLines" might do the trick:

Mathematica graphics

share|improve this answer
Thank you! This cleared it right up. – poorsod Jan 19 at 9:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.