mikeage.net Logo

mikeage.net @ ט׳ שבט תשפ״ג

Converting between DOS and Unix

Quick Overview

DOS (and Windows) use different formats to mark the ned of a line in a text file. DOS uses a CR-LF, while Unix just uses a LF. There are many ways to switch between the formats.. some common ones are below

Explicit Programs

The programs dos2unix and unix2dos provide a simple way to switch between the two formats. These are also known on some systems as todos and fromdos.


tr -d '\15\32' < dosfile > unixfile


DOS to Unix
awk '{ sub("\r$", ""); print }' < dosfile > unixfile
Unix to DOS
awk 'sub("$", "\r")' < unixfile > dosfile


DOS to Unix
perl -p -e 's/\r$//' < dosfile > unixfile
Unix to DOS
perl -p -e 's/\n/\r\n/' < unixfile > dosfile


Leave a Reply

Quick Map
Content +
Personal +
Archives +
Site Stuff +
RBS Weather +
Search +
Recent Images

Valid XHTML 1.1!
Printer Friendly Page

Last Modified: September 04, 2006 @ 02:11 CST

Memory(TRUE): 4194304/4194304
Memory(FALSE): 2998944/3008904