Excel saves tab delimited files without newline (UNIX/Mac os X) Excel saves tab delimited files without newline (UNIX/Mac os X) unix unix

Excel saves tab delimited files without newline (UNIX/Mac os X)


The problem is the actual character codes that define new lines on different systems. Windows systems commonly use a CarriageReturn+LineFeed (CRLF) and *NIX systems use only a LineFeed (LF).

These characters can be represented in RegEx as \r\n or \n (respectively).

Sometimes, to hash through a text file, you need to parse New Line characters. Try this for DOS-to-UNIX in perl:

perl -pi -e 's/\r\n/\n/g' input.file

or, for UNIX-to-DOS using sed:

$ sed 's/$'"/`echo \\\r`/" input.txt > output.txt

or, for DOS-to-UNIX using sed:

$ sed 's/^M$//' input.txt > output.txt


Found a pretty simple solution to this. Copy data from Excel to clipboard, paste it into a google spreadsheet. Download google spreadsheet file as a 'tab-separated values .tsv'. This gets around the problem and you have tab delimiters with an end of line for each line.


Yet another solution ...

  • for a tab-delimited file, save the document as a Windows Formatted Text (.txt) file type
  • for a comma-separated file, save the document as a `Windows Comma Separated (.csv)' file type