You can try the following code I quickly wrote. It's just a quick and simple hack. If you want to have command-line options, then you need to use the Getopt::Long module from CPAN.
use IO::File; use strict; # Load host list my $host = new IO::File "host.txt", "r" or die "Can not open host list file!"; my @hosts = <$host>; undef $host; foreach (@hosts) { chomp; s/\s+//g; # get rid of spaces } # Load input lines my $input = new IO::File "mainfile.txt", "r" or die "Can not open file!"; my @lines = <$input>; undef $input; foreach (@lines) { chomp }; # Create output files for hosts my $prefix = "mainfile_"; foreach (@hosts) { my ($hostname, $ipaddr) = split/,/; # Create the output file, and replace the # HOST and IP lines with actual data my $output = new IO::File "${prefix}${hostname}.txt", "w" or die "Can not create file!"; foreach my $txt (@lines) { if ($txt eq "HOST") { print $output "$hostname\n"; } elsif ($txt eq "IP") { print $output "$ipaddr\n"; } else { print $output "$txt\n"; } } # explicitly close the output file # not required, but good for the eye undef $output; }

In reply to Re: Can I copy a file and rename the file to many new files? by Roger
in thread Can I copy a file and rename the file to many new files? 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.