• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unix2dos command in perl script

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you miss my first reply?
 
"To do good, you actually have to do something." -- Yvon Chouinard
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic