#!/usr/bin/perl use strict; use warnings; use autodie; # usage: perl makeconfig.pl < host-ip.csv my $template_file_name="configtemplate.txt"; while(<>) { next if /^#/; chomp; my ($ip, $hostname, $location) = split (/,/); my $ofile_name=$hostname . ".txt"; open(TFILE, "< $template_file_name") || die "config template file $template_file_name: $!\n"; $ofile_name = $hostname . ".txt"; open(OFILE, "> $ofile_name") || die "output config file $ofile_name: $!\n"; while () { s/##location##/$location/; s/##hostname##/$hostname/; s/##ip##/$ip/; printf OFILE $_; } close OFILE; close TFILE; }