dtox, dos2unix, tofrodos

One of the joys of working in both the *nix and Windows worlds is that from time to time I get a text file in DOS format i.e. with a CR/LF in each line instead of just an LF. This means I get a Ctrl-M (^M) character at the end of each line and if it is supposed to be an executable script it will give some very strange errors.

There are a number of utilities on various Unix variants to convert these file and they are called things like dtox, dos2unix but on my Kubuntu system it took a bit of tracking down.

The package is called tofrodos so

sudo apt-get install tofrodos

will install the utilities for you. The utilities are called fromdos and todos and do exactly what they say on the tin.

One thing I like about these variants is they work on a file “in situ” so rather than having to do something like

dos2unix file1.txt > file2.txt

A simple

fromdos file1.txt

is all you need.

Advertisements

5 thoughts on “dtox, dos2unix, tofrodos

  1. In my Unisys unix days I would have killed for an application like this, regularly having to ftp files to/from PC’s for a range of applications.

    Normally setting the ftp switch to binary/ascii as appropriate (it’s been a long time) did the trick. If the file couldn’t be recovered, then it was good old ‘vi’ (is that still regularly used?). 1,$s/^M// – or some variation on that theme.

    Nostalgia’s not like it used to be – !ZZ

  2. Interesting post. I just use Emacs, to convert the encoding of the current file, you just use C-x ENTER f then the name of the encoding you want, i.e. in this case it would be unix (You can use tab completion to get a complete list of options). As with all editing commands, you need to save your changes of course.

  3. Once the tofrodos package is installed, the unix2dos and dos2unix commands will work, such as unix2dos file.txt and even unix2dos file.txt ~/Desktop/new-directory/file.txt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s