Text file end-of-line termination

One problem that I encounter regularly with file sharing text files between different clients; Whether it's a Solaris, UNIX/Linux client, a windows client, and even mac clients; Is how all three differ with how they handle/write the end-of-line termination in text files.

Solaris systems (like other flavours of Unix and Linux) use only a new-line character (dec 10, octal 12); Windows based systems use both a new-line and a carriage return (dec 10 and 13, octal 12 and 15); Whereas mac systems use only a carriage return (dec 13, octal 15).

Solaris provides two appropriately named utilities for translating text files from unix to dos and back again-- unix2dos and dos2unix. The dos2unix function could also be performed with standard Solaris commands:

$ cat myfile | tr -d '\015'

You could also use vi, and execute:

:1,$s/^M//g'

to strip all carriage returns from the file (use Ctrl-V Ctrl-M to generate the ^M character). Likewise, we can do the same for mac files:

$ cat myfile | tr '\015' '\012'

Examples

There are many possibilities, these are just mine. Here are a couple of examples:

The barber-pole effect

This output occurs when a file with only a new-line character EOL is displayed on a system expecting new-line and carriage return characters (ie, a windows system)

And did those feet in ancient time
                                  Walk upon England's 
mountains green:
                And was the holy Lamb of God,
                                             On Engla
nd's pleasant pastures seen!
                            And did the Countenance D
ivine,
      Shine forth upon our clouded hills?
                                         And was Jeru
salem builded here,
                   Among these dark Satanic Mills?
                                                  Bri
ng me my Bow of burning gold;
                             Bring me my Arrows of de
sire:
     Bring me my Spear: O clouds unfold!
                                        Bring me my C
hariot of fire!
               I will not cease from Mental Fight,
                                                  Nor 
shall my Sword sleep in my hand:
                                Till we have built Je
rusalem,
        In England's green & pleasant Land

The ^M syndome

This occurs when a file with both new-line and carriage return characters are displayed on a system expecting new-lines only

And did those feet in ancient time^M
Walk upon England's mountains green:^M
And was the holy Lamb of God,^M
On England's pleasant pastures seen!^M
^M
And did the Countenance Divine,^M
Shine forth upon our clouded hills?^M
And was Jerusalem builded here,^M
Among these dark Satanic Mills?^M
^M
Bring me my Bow of burning gold;^M
Bring me my Arrows of desire:^M
Bring me my Spear: O clouds unfold!^M
Bring me my Chariot of fire!^M
^M
I will not cease from Mental Fight,^M
Nor shall my Sword sleep in my hand:^M
Till we have built Jerusalem,^M
In England's green & pleasant Land^M