File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Perl and the fly likes unix2dos command in perl script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Languages » Perl
Bookmark "unix2dos command in perl script" Watch "unix2dos command in perl script" New topic
Author

unix2dos command in perl script

Susmitha Metlapalli
Ranch Hand

Joined: May 16, 2007
Posts: 44
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

Joined: Sep 07, 2004
Posts: 781

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.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4375
    
    8

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

Joined: May 16, 2007
Posts: 44
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

Joined: Sep 07, 2004
Posts: 781

Did you miss my first reply?
 
Consider Paul's rocket mass heater.
 
subject: unix2dos command in perl script