Convert newline between UNIX & DOS
0 votos
February 10th, 2007 toydi Posted in Text Manipulation, fromdos, hexdump, todos | Hits: 12531 |
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
Live Chat!









Leave a Reply