DOS and Windows have a different convention for newlines from Unix and Linux. In DOS, the newline character is a carriage return and a line feed, whereas in Unix it is just a linefeed. What this means is that there can be problems when dealing with files from one system on the other. The programs dos2unix and unix2dos will convert (by default "in place") a file from one system of newlines to the other.
[email protected]:~ > unix2dos INDEX
This will silently overwrite the original file with its Unix-style line endings with the DOS version (which you can give to your friend so he can read it in Notepad without embarrassment).
If you want to keep the original file, both dos2unix and unix2dos have a -n option that allows you to specify an output file:
[email protected]:~ > unix2dos -n INDEX INDEX.txt unix2dos: converting file INDEX to file INDEX.txt in DOS format ..." You can, in fact, achieve the same result as dos2unix with tr like this:
This removes the carriage return character that has the decimal value 13 represented by octal \15.
Was this article helpful?