• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unix2dos command in perl script

 
Susmitha Metlapalli
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing a perl script to call unix2dos command from a perl script to ensure that each line in a file will end with a carriage return and new line using following command.

system("unix2dos <filename>");

I have also tried executing the following command in perl script.

system("perl -i -p -e 's/\n/\r\n/' <filename>" );

but it is not giving the desired results.

OS is linux. Do we have to check any OS compatability to use above mentioned commands? Please suggest on this.

Thanks & Regards,
Susmitha.



 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little confused. Why is a Perl script needed for this? Why not just invoke unix2dos directly instead of via the Perl script?

P.S. It is almost trivial to write the equivalent of unix2dos in Perl without the need to invoke unix2dos using system().
P.P.S. Though I don't understand the need for this I suspect you need
where $file contains the filename.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Susmitha Metlapalli wrote:
I have also tried executing the following command in perl script.

system("perl -i -p -e 's/\n/\r\n/' <filename>" );

Maybe I'm misunderstanding something, but are you really calling an external command to run a perl script from within a perl script there? Why not just run the perl commands directly?
 
Susmitha Metlapalli
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have to run this perl script as a cronjob.

How to execute the following from within a perl script?

system("perl -i -p -e 's/\n/\r\n/' <filename>" );

I am not getting the desired result...

Is the above syntax same? do we need to declare anything in the perl script? like "use:"


Thanks,
Susmitha.


 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you miss my first reply?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic