Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PERL Search/Replacing Text Using external file 1

Status
Not open for further replies.

robersh

IS-IT--Management
Joined
Feb 9, 2004
Messages
2
Location
US
Hey there,
This sometimes works...other times doesn't??
The file it's using looks like this and is cleand up:

<cleancondjil> (ref'd below) looks like:
condition: s(oldjob)
condition: s(oldjob)
---want to replace oldjob with newjob

the <jobs> file loading array from looks like:
oldjob,newjob
-----This is the Searcher file below

open (IN, "<jobs") or die "Can't open $in_file: $!\n";


while ( $line = <IN> ) {
@fields = split /\s*,\s*/,$line;
$line=$fields[0],@fields[0];
$line2=$fields[1],@fields[1];
chomp ($line);
chomp ($line2);
# print "\n";
print "this is OLDJ: $line\n";
print "this is NEWj: $line2\n";

my $job1 = $line;
my $job2 = $line2;
chomp ($job1);
chomp ($job2);


#Modifies conditions in OLDJOB JIL file: $job.depjil with NEW jobname - $job2
#This step changes JIL condition statements for jobs frmrly dep on $job1 to dep on $job2
print "NEW JIL for Jobs modifed to update from file cleancondjil and located in cleancondjil2\n";

open(DEPFILE, "<cleancondjil"); # open for input
open(DEPOUTFILE, ">cleancondjil2");
while(<DEPFILE>)

{
my($line) = $_;
# $line =~ tr/[a-z]/[A-Z]/;
$line =~ s!s\($job1\)!s\($job2\)!g;
# $line =~ s/ASNBRSCA_FW/\($job2\)/g;
$line =~ s/f\($job1\)/f\($job2\)/g;
$line =~ s/nr\($job1\)/nr\($job2\)/g;
$line =~ s/n\($job1\)/n\($job2\)/g;
$line =~ s/insert/update/g;
print DEPOUTFILE "$line";
# print "$job1\n";
# print "$job2\n";
# print "$line";
}

close(DEPFILE);
close(DEPOUTFILE);
}
close (IN);
 
is the jobs file always just a one line file? Is this schoolwork?

- Kevin, perl coder unexceptional!
 
no, it looks like this...so many lines.

Man, I'd sure love if you know the answer!! ;-) Thanks.

ASNBRSCA_FW,UOPS_DLY_CANASNBRS_fw_ASNBRSCA_TRIG
ASNBRSCA_DEL,UOPS_DLY_CANASNBRS_del_ASNBRSCA_TRIG
PWB11205_FTP,UOPS_DLY_CANASNBRS_ftp_WR11205
PWB11225_FTP,UOPS_DLY_CANASNBRS_ftp_WR11225
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top