Wednesday, 23 June 2010

Working with DOS formattted files on Ubuntu

I was trying to hack an installation script this morning, and noted that VI was showing me Carriage Return/Line Feed symbols at the end of each line, indicating that the file had last been edited on a Windows platform using a tool such as Notepad.exe.

I can see this because each line ends with the special characters ^M which is the ASCII code for CR/LF.

In the past, I've always used the dos2unix command to strip these out of a file.

However, dos2unix no longer appears to be installed out-of-the-box with Ubuntu 10.04 or, worse still, available via the normal Canonical repositories; I tried installing it using the command: -

sudo apt-get install dos2unix

but got the "Computer says 'NO'" message of: -

E: Couldn't find package dos2unix

Googling around, I found this blog posting: -

which refers to a different package - tofrodos - which provides similar functionality.

I installed it using a similar command: -

sudo apt-get install tofrodos

accepting the warning that this package isn't certified as being an official part of Ubuntu.

Once done, I get two new commands: -


which equate to my old friends: -



Sweet :-)


Pierrick said...

Thank you, I use very often dos2unix and I was really wondering it was! (I use it on the project to convert patch files send by contributors running on Windows.

Dave Hay said...

Pierrick - glad to be of use :-)