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
Knowing If a Remote Port Forward Was Successful
Export_Symbol in Kernel Module | Undefined Symbol During Insmod
Using Ssh to Run a Cleartool Command with Agruments on Remote a Linux MAChine
Bash/Linux Sort by 3Rd Column Using Custom Field Seperator
Using Gzip to Compress Files to Transfer with Aws Command
How to Ask Bash for the Current Options
Unable to Set Variable in Case Statement Bash
Making Proprietary Elf Binaries Portable on Linux
Simple Way to Get Filesize in X86 Assembly Language
Safely Remembering Ssh Credentials in Bash Script
How to Disable Hardware Prefetcher in Core I7
Use Bash Variable Within Slurm Sbatch Script
How to View Thread Id of a Process Which Has Opened a Socket Connection
How to Overlap and Merge Multiple Audio Files Using Ffmpeg
A Way to Prevent Bash from Parsing Command Line W/Out Using Escape Symbols