in reply to Re: Can I copy a file and rename the file to many new files?
in thread Can I copy a file and rename the file to many new files?

Thanky very much for the quick answer.
The code works great!.
I have only one more question.
If the "MAINFILE.TXT" also contain the HOST and IP on several lines like this.
"MAINFILE.TXT"
someinfo
HOST
IP
someinfo
This is my computer HOST and it has the adress IP.
someinfo someinfoHOSTsomeinfo
How can I also replace these?.

Yes It it should be one line
someinfo someinfoHOSTsomeinfo


//Anders Andersson
  • Comment on Re: Re: Can I copy a file and rename the file to many new files?

Replies are listed 'Best First'.
Re: Re: Re: Can I copy a file and rename the file to many new files?
by Roger (Parson) on Sep 28, 2003 at 21:31 UTC
    If you want to replace all occurances of HOST and IP in your mainfile.txt during the copy process, you just need to replace the printing part:

    ... foreach my $txt (@lines) { # replace HOST and IP with $hostname and $ipaddr $txt =~ s/HOST/$hostname/g; $txt =~ s/IP/$ipaddr/g; print $output "$txt\n"; }
    This will replace ALL occurances of HOST and IP in your mainfile.txt.
      Hello

      Thank you very much for all your help.


      //Anders Andersson
      Hello

      I must ask you again about this script.
      I was trying this script but every file that are being created have the same info in it.

      These files have been created.
      mainfile_host1.txt
      mainfile_host2.txt

      Both of these file contain this info.
      someinfo
      host1
      192.168.1.1
      someinfo
      This is my computer host1 and it has the adress 192.168.1.1 someinfo someinfohost1someinfo

      I want the the file mainfile_host2.txt contain this info.
      someinfo
      host2
      192.168.1.2
      someinfo
      This is my computer host2 and it has the adress 192.168.1.2 someinfo someinfohost2someinfo

      But it want do that.


      //Anders Andersson