• dos2unix alternative

    by  • July 12, 2011 • Scripting, UNIX/Linux • 0 Comments

    If you need to convert a DOS text file to a UNIX text file, and the dos2unix command is not available on your platform, you can achieve the same result by using the tr command to remove the carriage return (CR) byte from each line:

    cat mydosfile.txt | tr -d '\015' > myunixfile.txt

    On DOS, the end of a line is identified by 2 bytes; ASCII codes 0x0Dh (Carriage Return – CR) followed by 0x0Ah (Line Feed – LF), or CR+LF short. On UNIX/Linux, the end of a line is identified by a single byte 0x0Ah, or LF short. With the tr command we simply need to remove the 0x0Dh byte from each line to convert CR+LF to just LF. Since the tr command accepts ASCII codes in the octal format, we would specify ‘\015′ to represent the 0x0Dh hexadecimal number (or 13 decimal).

    Leave a Reply

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


    *