Unix2dos: Difference between revisions

From Leo's Notes
This page was last edited on 15 June 2020, at 00:13.
Created page with "A newline is denoted with different control characters depending on the operating system you are on. Linux denotes newlines with a line feed ({{code|LF}}, denoted typically a..."
 
m added categories
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
A newline is denoted with different control characters depending on the operating system you are on.
Unix2dos is a utility that can convert the newline endings between Unix like systems (Linux, MacOS, BSD, etc.) that uses {{code|\n}} and DOS like systems (DOS, FreeDOS, Windows) that uses {{code|\r\n}}.


Linux denotes newlines with a line feed ({{code|LF}}, denoted typically as {{code|\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.  
 
Windows and DOS denotes newlines with both a carriage return and a line feed ({{code|CR LF}}), denoted typically as {{code|\r\n}}.


== Conversion ==
== Conversion ==
Line 16: Line 14:
$ unix2dos
$ unix2dos
}}
}}
{{Navbox Linux}}[[Category:Linux]]
[[Category:LinuxUtilities]]

Latest revision as of 00:13, 15 June 2020

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