Kevin Basil (signature)

Converting Text Files

Next article: US Scientist: OK with Killing Embryos, Not OK with Personal Profit from Research
Previous article: Vatican Again Defends Scientific Description of Creation

Written by Basil on 11/12/2005 1:05 PM. Filed under:


Share    
Share with your friends and followers:
Share

How do I convert between Unix and Mac OS text files?

I’m mostly blogging this so I can remember where to find this stuff in the future. Thanks to lsald on ##mac (irc.freenode.net) for pointing it out.

If you open a file saved in TextEdit.app in a command-line text editor like vi, the line feed characters are all wrong. The file ends up as one huge line with a bunch of blue “^M” characters. The link above gives several command-line options for switching the offending characters out for Unix-style line feeds (and back again, if you were silly enough to want that).

Share with your friends and followers:
Share


Share   

The URL to trackback this post is:
http://kevinbasil.com/2005/11/12/converting-text-files/trackback/

One Response to “Converting Text Files”

  1. sockmonk Says:

    Handy. It helps knowing that those ^M characters are really \r characters.

    Here’s a variation on the perl one if you don’t mind just fixing the file in place instead of writing it out to a new one:

    perl -pi -e ‘s/\r/\n/’ file.txt

    it’s untested, but should work as well as it does for other substitutions. It’s my current one-liner to memorize, so I don’t have to keep trying to figure out how to get sed to edit a file in place. If you really want a backup, I think this will give you one:

    perl -pi.bak -e ‘s/\r/\n/’ file.txt