Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dos2unix?

Tags:

linux

perl

I am learning perl programming. I have run a perl script in windows platform but I need to run it in Linux platform like in Ubuntu. My script run perfectly in windows but not in Linux. I am not familiar with dos2unix tool. I am struggling about how to use it in my windows 7 and how to convert my winfile to unixfile. Suppose my perl script is test.pl and coding are inside. Now how can I make this script work properly in Linux using dos2unix tool? Besides, where should I unzip dos2unix tool?

like image 213
SSh Avatar asked Apr 22 '14 04:04

SSh


2 Answers

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 \).

like image 178
merlin2011 Avatar answered Oct 20 '22 21:10

merlin2011


Another option would be to use a text editor on windows that supports UNIX line endings.

Which text editors handle both Windows- and Unix-style line breaks properly?

like image 29
Osama Al-Maadeed Avatar answered Oct 20 '22 21:10

Osama Al-Maadeed