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

- 45
- 5

- 71,677
- 44
- 195
- 329
-
@SSh, Please update your question with exactly what you mean by "those commands aren't working". – merlin2011 Apr 22 '14 at 05:02
-
I am using Ubuntu. I tried "sudo apt-get dos2unix" and "sudo yum install dos2unix" commands aren't working. – SSh Apr 22 '14 at 05:13
-
@SSh, On Ubuntu the first command should work unless you are not an admin on your server. What error do you get? – merlin2011 Apr 22 '14 at 05:14
-
@SSh, Also I assume you are opening a terminal and typing these commands, rather than in the Ubuntu search utility. – merlin2011 Apr 22 '14 at 05:15
-
You are correct. I am using ubuntu from my pendrive. Can't find Ubuntu search utility. – SSh Apr 22 '14 at 05:21
-
@SSh, I hope your acceptance of the answer implies that you got it to work. – merlin2011 Apr 22 '14 at 05:25
-
I can't find any search utility in MAC OS X. Only can find terminal. Can you help pls? – SSh Apr 23 '14 at 20:25
-
@SSh, I think you are looking for spotlight. Go to the top right corner of your screen and click on the icon that is up there. – merlin2011 Apr 23 '14 at 20:34
-
That is just a search option. I am looking for what you told me to do. I need to use sudo apt-get dos2unix command. But where can I use this? i can just find terminal on MAC – SSh Apr 23 '14 at 20:44
-
@SSh, There is no `apt-get` on OSX, because it is not Debian-based. Unfortunately, I do not possess an Apple machine, so I do not know the details of OSX's package manager. If you cannot find it online, you may have to ask a new question. – merlin2011 Apr 23 '14 at 20:47
-
I have just added the code I am struggling with. Can you make time to check the code? – SSh Apr 23 '14 at 21:07
-
@SSh, Please ask a new question rather than modifying an existing question. – merlin2011 Apr 23 '14 at 21:23
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?

- 5,654
- 5
- 28
- 48