Saturday, February 11, 2012

Ways to convert several DOS files into UNIX file

Usually I use the same vim scripts in Windows and Linux. Sometimes I copy the scripts from Windows to Linux and they still in dos format. Therefore when the scripts executed some errors come out because of the difference between Windows' and Linux's carriage line format.

Below is my way to convert several dos files into unix file

Using dos2unix

Using dos2unix tool is the simplest way, I just run below command $ find ~/.vim -name "*.vim" -print0 | xargs -0 dos2unix

Using fromdos

To use fromdos tool I need to make a bash script like below: #!/bin/sh list=`find ~/.vim -name "*.vim" -print` for files in $list; do fromdos < $files > $files-x mv $files-x $files done