dos2unix - Convert Windows ASCII file to Unix ASCII file - Strip the CRs from a file

ASCII text files can contain different forms of newlines, depending on which operating system is being used. Converting between these formats is often necessary if you use several operating systems. The flip program will convert the newlines to any format given in the table below:

Operating System   Newline Character(s)

Microsoft Windows / Windows   0Dh 0Ah
Unix (e.g., Linux), also Apple OS X and higher   0Ah

Oracle Solaris systems

To convert a Windows file to a Unix file, enter:

dos2unix winfile.txt unixfile.txt

To convert a Unix file to Windows, enter:

unix2dos unixfile.txt winfile.txt


In vi, you can remove carriage return ( ^M ) characters with the following command:


Note: To input the ^M character, press Ctrl-v , and then press Enter or return.

C dos2unix source code