update: sorry -- I missed this part in your OP: "how i can convert a list of files, stored in a 'list file'" I have added a bit to the script to account for this. As modified, you can pipe a list of file names to the script on stdin (e.g. "ls | script.pl") or store the list(s) in some named file(s) and give the list file name(s) to the script as ARGV (e.g. "script.pl list [list2 ...]" /update.

Well then, you could create a perl script file as follows:

#!/usr/bin/perl # in-place dos-to-unix conversion (remove ^M's): my @file_list = <>; # update: adding these two lines to chomp @file_list; # read a list of file names for my $file ( @file_list ) { # not "@ARGV" open( I, $file ) or die "$file: $!"; open( O, ">$file.unx" ) or die "$file.unx: $!"; while (<I>) { s/\cM*//g; print O; } close I; close O; rename "$file.unx", $file or die "renaming $file.unx to $file: $!" +; }

Note that this differs slightly from the code in your original post: your strange and less efficient approach would cause each "CRLF" sequence in a dos file to be converted to "LFLF", which means your output files would have twice as many "lines" as the originals, and half of those output lines would be empty. The version here simply removes the "CR". (Or maybe it was your intention that dos files should show up in unix as "double-spaced"?)


In reply to Re: Re: Re: Another dos to unix question by graff
in thread Another dos to unix question by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.