Could you help me how to fix my code so I can get the expected output as seen below?
is there missing in my program?
Thank You
Code:
#!/usr/bin/perl -w
use strict;
open (FH, "< file1.log") or die $!;
open (FL, "< file2.log") or die $!;
my $file = "result.log";
my ($afile, $bfile);
foreach my $lines (<FH>){
chomp $lines;
($afile, $bfile) = split (/\s+/,$lines);
if (open(FC, "> $file")){
while (<FL>){
if ($_ =~ /$afile/){
print FC $_;
}
}
}
close (FC);
}
close (FH);
close (FL);
__DATA__
file1.log:
unix1 test
unix2 test
file2.log:
unix1 halo halo
unix2 halo halo
unix3 halo halo
------
Code:
Unexpected result:
unix1 halo halo
Code:
The expected result:
unix1 halo halo
unix2 halo halo
---------- Post updated 08-03-13 at 05:34 AM ---------- Previous update was 08-02-13 at 10:47 PM ----------
Done by my self. Here is the code:
Code:
#!/usr/bin/perl -w use strict; open (FH, "< file1.log") or die $!; open (FL, "< file2.log") or die $!; my @temp = <FL>; my $file = "result.log"; my ($afile, $bfile); foreach my $lines (<FH>){ chomp $lines; ($afile, $bfile) = split (/\s+/,$lines); if (open(FC, "> $file")){ foreach (@temp){ if ($_ =~ /$afile/){ print FC $_; } } } close (FC); } close (FH); close (FL);
Hi,
I have the following, it doesn't work and I know it's crap code.
The objective is to split a file with a givin number of codes such as:
01,02,03,...,99
Then return all records with each seperate identifier in a new file.
The files being split have lrecl=500, recfm=F, and I... (4 Replies)
I am getting a :; then
echo "Enter zero or one file"
echo "You must use a valid directory"
echo "Current directory is:" pwd
exit 0
fi
#Flag Variable
flag=1
#Code for no arguments
if ; then
for filename in *
do
if ; then
... (2 Replies)