hoopajoo.net
The ^M that followed you home from DOS/Windows
The ^M that followed you home from DOS/Windows
⇐ Back to Administration

Questions, comments, or corrections? Send me a message.

One thing that I find very irritating is that DOS/Windows use cr/lf format for terminating a line, while Linux uses only the lf (cr=carriage return,lf=line feed). Many times when you copy a text file from DOS to your Linux system, the file will be littered with ^M (that's ctl-M) characters at the end of every line. An offending file might look like this:

         0  |     1 | Axis X1^M
         2  |     4 | Axis X2^M
         4  |    16 | Button A^M
         5  |    32 | Button B^M
         6  |    64 | Button C^M
         7  |   128 | Button D^M
        12  |  4096 | Pad Button X^M
        13  |  8192 | Pad Button Y^M
        14  | 16384 | Pad Button U^M
        15  | 32768 | Pad Button V^M
To get rid of them, use the fromdos command:
fromdos < DOSFILE.TXT > linuxfile.txt
And the DOSFILE.TXT will be stripped of the annoyance and put in linuxfile.txt. Similarly, if you are using Linux in a windows camp and are finding that others can't read your text files, you can use the todos command to insert those ^M's for you like this:
todos < linuxfile.txt > DOSFILE.TXT
Using todos/fromdos you can make living in a Windows World a little easier for your Linux box.