$envfile="/root/env.properties";
@envFile=<$env>;
open my $env, '<', $envfile or die "Can't read old file: $!";
####
open my $in, '<', $file or die "Can't read old file: $!";
open my $out, '>', "$file.new" or die "Can't write new file: $!";
####
print "\nFile contents:";
print @envFile;
foreach $envline (@envFile){
while ( <$in> ){
####
print "$. $_";
if($envline =~/$DOMAIN_DB_CONN_STR=.*:1521:.*/ && $_=~/$DOMAIN_DB_CONN_STR=.*:1521:.*/){
####
print "\nMatch";
$line=$_;
$line =~ s/$DOMAIN_DB_CONN_STR=.*:1521:.*/NUANCE_DB_CONN_STR=$dbhost:$dbport:$dbschema/;
####
print $out $line;
}
}
}
####
use strict;
use warnings;
my $envfile = "/root/env.properties";
my $file = 'input.txt'; # Or whatever
open my $env, '<', $envfile or die "Can't read old file: $!";
open my $in, '<', $file or die "Can't read old file: $!";
open my $out, '>', "$file.new" or die "Can't write new file: $!";
my @envFile = <$env>;
my @inFile = <$in>;
print "\nFile contents:";
print @envFile;
my $dbhost = '';
my $dbport = '';
my $dbschema = '';
foreach my $envline (@envFile){
my $inLineCount = 0;
foreach my $inline (@inFile){
$inLineCount++;
print "$inLineCount $inline";
foreach my $DOMAIN_DB_CONN_STR ('FINANCE_DB_CONN_STR', 'MARKETING_DB_CONN_STR') {
if($envline =~/$DOMAIN_DB_CONN_STR=.*:1521:.*/ && $inline =~/$DOMAIN_DB_CONN_STR=.*:1521:.*/){
print "\nMatch";
my $line = $inline;
$line =~ s/$DOMAIN_DB_CONN_STR=.*:1521:.*/NUANCE_DB_CONN_STR=$dbhost:$dbport:$dbschema/;
print $out $line;
}
}
}
}