Converting from Mac to Unix line endings

Posted: March 10th, 2010 | Author: Rob Searles | Filed under: Linux, Tutorials | Tags: | Comments

This is more a post for me than anyone else, but I thought I’d share anyway.

In our team we have a mixture of Linux and Mac users, and we are constantly editing the same files. One of the most irritating things is when a file is saved with Mac line endings instead of Unix line endings (displaying as ^M in Emacs). This happens very rarely, but on the occasion it does I can quickly convert back using the following commands on my Linux box:

$ tr '\r' '\n' < file-in-question.txt > tmp.file
$ mv tmp.file file-in-question.txt

Works perfectly

If you want to find more about the tr (Translate) program, visit the man page.

If you liked this post, please share it:
  • Digg
  • Reddit
  • Sphinn
  • Facebook
  • del.icio.us
  • YahooMyWeb
  • Furl
  • Mixx
  • Google
  • Fark
  • Live
  • MisterWong
  • StumbleUpon
  • Technorati
  • TwitThis
  • BlogMemes
  • Blogsvine
  • Ma.gnolia
  • Pownce
  • Spurl

Related Posts


blog comments powered by Disqus