Tuesday, 27 November 2012

Convert the files from Windows os to unix/linux format and vice versa using tofrodos

The problem we face in linux or unix world is that we will be working in linux but rest of the world depends on Windows. So like the files we get. Most of the files are from Windows and we need to process these files in linux.

It is just too much expensive to have Windows copy running side by side or in Virtual Machine to process these Windows files. Luckily we already have the solutions for this. Here comes the software called tofrodos handy for all of us.

There are two parts for this software. One is called 'fromdos' and other is called 'todos'. From the name itself we can understand that what it does. Both are command line software which means that we need to use terminal commands to process the files but is very simple enough to handle all these with basic linux knowledge.

Fromdos converts the files from Windows world to unix/linux format and todos do the opposite. Using the software is also simple enough. For example, one of our client which uses Windows gives us a file which has data and we need to load it in our Ubuntu linux server's Mysql database. We are loading the file using the command 'load data local infile' and gives the proper delimiter but once it is loaded, the out put is not what we expected. Even though we are giving correct delimiter, data has been loaded to mysql not in correct format. Later we found out that issue is because the file is from Windows world.

Here comes the fromdos software helpful. Just type the below command try loading it again and you can see that it works fine this time. Type the below command to convert it from Windows format to unix/linux format.

fromdos filename

That's all. You can install the fromdos and todos packages using the command:

sudo apt-get install tofrodos

No comments:

Post a Comment