Dos2Unix Command

Convert DOS/Windows line endings to Linux line endings in Vim

dos2unix is a commandline utility that will do this, or :%s/^M//g will if you use Ctrl-v Ctrl-m to input the ^M, or you can :set ff=unix and Vim will do it for you.

There is documentation on the fileformat setting, and the Vim wiki has a comprehensive page on line ending conversions.

Alternately, if you move files back and forth a lot, you might not want to convert them, but rather to do :set ff=dos, so Vim will know it's a DOS file and use DOS conventions for line endings.

How to use dos2unix?

You should be able to get dos2unix from your package manager on Linux.

If you are using a Debian-based distro, you should be able to do sudo apt-get install dos2unix.

If you are using a RH-like distro, you should be able to do sudo yum install dos2unix.

Once it is installed, you can just give the target file as an argument'

dos2unix test.pl

Also, note that this may not be the only problem you might run into while trying to move a script to Linux from Windows.

For example, if you are invoking any external tools in your script, those tools will probably have different names or not exist at all on the other platform.

Also, if you are using any relative file paths with path separators, the separator is different on Linux (which uses /) than Windows (which uses \).



Related Topics



Leave a reply



Submit