Code:
$
$
$ # display the contents of the data file "f1"
$
$ cat f1
red blue
white black
$
$
$ # display the contents of the Perl program that processes "f1"
$
$ cat -n f1.pl
1 #!perl -w
2
3 # The template string uses here-doc to take care of multiple lines and single/double quotes
4 $template = <<END;
5 "'',165,1293537000,0,'Logs - ABC','\$FIRST','*Log*.log','/usr/apps/collectors/\$FIRST/log',60,'no',120,'yes',180,'yes'"
6 "'',198,1295520870,0,'ABC_INBOUND','\$FIRST','*\$SECOND*','/usr/apps/\$FIRST/BR_ABC/ARCHIVE',60,'no',120,'no',180,'yes'"
7 END
8
9 # process the file now
10 open (FH, "f1") or die "Can't open f1: $!"; # open file and assign file handle
11 while (<FH>) { # while we can read records
12 chomp; # remove the newline at the end
13 ($first, $second) = m/^\s*(\w+)\s*(\w+)\s*$/; # split record into two fields $first and $second, using regex
14 $line = $template; # assign template to the line we are going to work with
15 $line =~ s/FIRST/$first/g; # substitute first and second fields
16 $line =~ s/SECOND/$second/g;
17 print $line; # and print the line
18 }
19 close (FH) or die "Can't close f1: $!"; # clean up when it's all done
$
$
$ # Now run the Perl program
$
$ perl f1.pl
"'',165,1293537000,0,'Logs - ABC','$red','*Log*.log','/usr/apps/collectors/$red/log',60,'no',120,'yes',180,'yes'"
"'',198,1295520870,0,'ABC_INBOUND','$red','*$blue*','/usr/apps/$red/BR_ABC/ARCHIVE',60,'no',120,'no',180,'yes'"
"'',165,1293537000,0,'Logs - ABC','$white','*Log*.log','/usr/apps/collectors/$white/log',60,'no',120,'yes',180,'yes'"
"'',198,1295520870,0,'ABC_INBOUND','$white','*$black*','/usr/apps/$white/BR_ABC/ARCHIVE',60,'no',120,'no',180,'yes'"
$
$