Convert newline between UNIX & DOS

February 10th, 2007 toydi Posted in fromdos, hexdump, Text Manipulation, todos | Hits: 39383 | 1 Comment »

There are several ways to convert newlines between UNIX-style (LF) and DOS-style (CR+LF).

I like todos, fromdos commands (or unix2dos, dos2unix) for their simplicity. Sometimes they are not installed by default, try to search your repository for a tofrodos package .

Let's try. Simply create a text file, foo.txt that contains a newline:

aaa
bbb

A UNIX newline (LF) is represented by x0A:

$ hexdump foo.txt
00000000  61 61 61 0a 62 62 62     |aaa.bbb|

To convert it to DOS newline (CR+LF, represented by x0D+x0A):

$ todos foo.txt
$ hd foo.txt
00000000  61 61 61 0d 0a 62 62 62     |aaa..bbb|

To convert it back to UNIX newline:

$ fromdos foo.txt

You can use file command to tell whether a text file is in DOS-style:

$ file dosfile.txt
dosfile.txt: ASCII text, with CRLF line terminators

One Response to “Convert newline between UNIX & DOS”

  1. [...] Convert newline between UNIX & DOS » Linux by ExamplesFeb 10, 2007 … To convert it to DOS newline (CR+LF, represented by x0D+x0A): $ todos foo.txt $ hd foo.txt … convert wallpaper format and size examples … [...]

Leave a Reply