Unix2dos

From Leo's Notes
(Redirected from Newline)
Last edited on 15 June 2020, at 00:13.

Unix2dos is a utility that can convert the newline endings between Unix like systems (Linux, MacOS, BSD, etc.) that uses \n and DOS like systems (DOS, FreeDOS, Windows) that uses \r\n.

The conversion is necessary when dealing with files across these two platforms where the new line endings are important such as when dealing with scripts.

Conversion

On Linux, use any one of:

## From \r\n to \n:
$ dos2unix
$ cat file.txt | tr -d '\r' > file2.txt

## From \n to \r\n:
$ unix2dos