How to use dos2unix?

19,885

Solution 1

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

Solution 2

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?

Share:
19,885
SSh
Author by

SSh

I am a beginner in Perl Programming. I want to learn perl. I need your cooperation.

Updated on July 23, 2022

Comments

  • SSh
    SSh almost 2 years

    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?

  • merlin2011
    merlin2011 about 10 years
    @SSh, Please update your question with exactly what you mean by "those commands aren't working".
  • SSh
    SSh about 10 years
    I am using Ubuntu. I tried "sudo apt-get dos2unix" and "sudo yum install dos2unix" commands aren't working.
  • merlin2011
    merlin2011 about 10 years
    @SSh, On Ubuntu the first command should work unless you are not an admin on your server. What error do you get?
  • merlin2011
    merlin2011 about 10 years
    @SSh, Also I assume you are opening a terminal and typing these commands, rather than in the Ubuntu search utility.
  • SSh
    SSh about 10 years
    You are correct. I am using ubuntu from my pendrive. Can't find Ubuntu search utility.
  • merlin2011
    merlin2011 about 10 years
    @SSh, I hope your acceptance of the answer implies that you got it to work.
  • SSh
    SSh about 10 years
    I can't find any search utility in MAC OS X. Only can find terminal. Can you help pls?
  • merlin2011
    merlin2011 about 10 years
    @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.
  • SSh
    SSh about 10 years
    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
  • merlin2011
    merlin2011 about 10 years
    @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.
  • SSh
    SSh about 10 years
    I have just added the code I am struggling with. Can you make time to check the code?
  • merlin2011
    merlin2011 about 10 years
    @SSh, Please ask a new question rather than modifying an existing question.