Steven Penny Steven Penny - 1 year ago 74
Bash Question

Convert line endings

I have been using

to convert line endings. After installing Puppy Linux I
noticed that it does not come with
, but
. Then I noticed that
Ubuntu is missing both by default.

What is another way to convert line endings?

Answer Source

Doing this with POSIX is tricky:

  • POSIX Sed does not support \r, \xD or \15

  • Even if it did, the in place option -i is not POSIX

  • POSIX Awk does support \r and \15 but not \xD

  • However Awk’s -i inplace and -l inplace syntax are not POSIX

  • d2u and dos2unix are not POSIX utilities, but ex is

  • POSIX ex does not support \r, \xD or \15

  • POSIX tr supports \r and \15 but not \xD

To remove carriage returns:

ex -bsc '%!tr -d \\r' -cx file

To add carriage returns:

ex -bsc '%s/$/\n/|%!tr \\0 \\r' -cx file
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download