Sunday, April 1, 2007

Utility Assistance: dos2unix

I had known of the utility "dos2unix" for some time, but I never had occasion to use it until recently. I have been working on a script to assist in system administration, and had put in Yahoo! Briefcase so that I could access the single file on various systems. In the process, it got Windows formatting added in (open such a file in vim, for example, and you will see "^M" characters peppering each line). This causes no end of errors when the script is run on a linux system.

So, I thought I would try the dos2unix command I had read about. Command not found... sudo apt-get? Nope. Not in the repos. It turns out that the utility is called "tofrodos" (that's right, no "m") in the repos, with the added explanatory note "alias tofromdos". So I installed this, and tried to run "tofromdos". Not found.

After some searching, I found that once tofrodos is installed, you can run "dos2unix [filename]", and it runs as you would expect. I am still not sure why, but at least the utility is useable.


Blogger Duncan McGreggor said...

Do you know about setting the file format in vim? If you do ":set ff=unix" and ":set ff=dos" in vim, you will respectively convert the file from whatever it was to UNIX line endings or DOS/Windows line endings (though why you would ever do the latter, I cannot imagine).

April 2, 2007 at 2:01 PM  
Blogger by Immortal Curiosity said...

I did not know this, but will add it post haste! I assume it is added to .vimrc?

The utility is still handy for files that one does not need to open, just convert and then do whatever. But this setting will be a great addition.


April 2, 2007 at 2:07 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home