Thursday, March 1, 2007

Fixing Line Breaks in Perl

Here is a handy Perl one-liner that I use a lot:

perl -pi -e 's/\r/\n/g' FILENAME

This one is useful for Excel Spreadsheets in OS X. When you export data into a delimited file and then open it in VI, the line breaks don't show up. At least, that's what happens with my very old version of Excel. Using the above one-liner on the file converts the carriage returns into line breaks that VI can interpret properly.

There's a much more thorough explanation here, which is where I got the idea from initially.