After reading a Windows user’s nightmare of having to convert hundreds of files, I thought I’d post this solution. If you need to convert Windows line endings to Mac / Unix ones, you need to execute this command in Terminal. (This solution doesn’t add extra line-endings that some do)
$ cd /directory/with/your/files
$ find . -type f -exec perl -pi -e 's/\r\n?/\n/g' {} \;
The above works recursively. If you are a bit afraid of going recursive this is better:
$ cd /directory/with/your/files
$ perl -pi -e 's/\r\n?/\n/g' *
This above may through up some errors if it tries to convert directories, so you can be more specific if the file names have a pattern like : a.txt ; b.txt; c.txt; etc.
$ cd /directory/with/your/files
$ perl -pi -e 's/\r\n?/\n/g' *.txt
A good point to note that a command - period will interrupt a command if you go wrong. This is definitely one to put in your .profile file:
alias fle="perl -pi -e 's/\r\n?/\n/g'"
alias fler="find . -type f -exec perl -pi -e 's/\r\n?/\n/g' {} \;"
Then you can just do
$ fle *
$ fler
[Fle = fix line endings ]


0 Responses to “Convert Windows Line endings to Unix / OS X”