Apple Intelligence now features Image Playground, Genmoji, Writing Tools enhancements, seamless support for ChatGPT, and visual intelligence.

Apple Intelligence has also begun language expansion with localized English support for Australia, Canada, Ireland, New Zealand, South Africa, and the U.K. Learn more >

You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

converting dos line endings to unix

What is the simplest way a Macintosh user can convert a text file with DOS/Windows (CRLF) line endings to Unix/Mac (LF) using only the tools available in a standard OS X distribution?


In the command-line environment (Terminal), I don't see the old standard, dos2unix. And I don't see an option in TextEdit to specify which. More capable text editors, e.g., TextWrangler, have such an option, but I don't want to require the user to have to download anything more.


I want to share some Perl scripts I wrote with other Macintosh users. The scripts work on text files with Unix/Mac (LF) line endings, but the users' files on which the scripts operate may have DOS/Windows (CRLF) line endings. I want to tell them how to convert their files without having to install anything more.


Is that even possible? Seems like it should be.

MacBook Pro (17-inch Early 2011), OS X Mavericks (10.9.2)

Posted on Feb 22, 2015 5:36 AM

Reply
Question marked as Top-ranking reply

Posted on Feb 22, 2015 6:46 AM

Since you are already using Perl, why not use that? For example:

perl -pe 's/\r\n/\n/g' inputFile > outputFile
7 replies

Feb 22, 2015 9:44 AM in response to Ken Nellis

Using Automator, one can make a Desktop application that simulates dos2unix.


The Automator application shown here, will prompt the user to choose one or multiple (using command key) text files, and will then use Perl to process each file in-place, replacing the carriage return-line feed pairs with just a line feed. I tested this on a folder of text files where each file had more than 1 CRLF pair. Afterwards, there were only LF. The last thing this application does is slide out an OS X notification with processing status and number of files affected. I borrowed, and adapted the Perl block from Stack Overflow.


User uploaded file

User uploaded file

converting dos line endings to unix

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.