mikeage.net Logo
mikeage.net/2005/08/12/converting-between-dos-and-unix/

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

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

AWK

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

Perl

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

Enjoy.

Leave a Reply

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

Valid XHTML 1.1!
Screen Pge
 

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

Memory(TRUE): 4194304/4194304
Memory(FALSE): 2994376/3004360