Monday, June 14, 2010

convert dos file to linux file

We often use the commands to convert the dos file to linux, using the commands

dos2unix - DOS/MAC to UNIX text file format converter
unix2dos - UNIX to DOS text file format converter


The conversion can be done by the commands tr and sed.

$ tr -d \\r < dos-file.txt > temp.txt && mv temp.txt dos-file.txt

here dos-file.txt will be converted to unix fileformat, temp.txt is the temporary file created and then renamed to dos-file.txt

$ sed -e 's/$/\r/g' unix-file.txt > temp.txt  && mv temp.txt unix-file.txt
here unix-file.txt will be converted to dos fileformat, temp.txt is the temporary file created and then renamed to unix-file.txt.

No comments:

Post a Comment