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

Your email address will not be published. Required fields are marked *