hi,
i m having 2 files say F1 and F2.
there are some joining conditions like:
Column 4 from F1= Column 29 from F2;
Column 10 from F1= Column 165 in F2;
and if value in column 8 from F2='3'
than i should get Column 4,5,8,10 from F1 and 29,165 from F2.
I cant provide the files. but the files are pipe-delimited means each column is seperated by |.
please provide me the help in this case.
Thanks
to get quick responses, tell something more about what are you trying to archive
hi,
Actually i have sql queries and with those queries i want to check the feed files in unix.
so i have the joining condition as:
Column 4 from F1= Column 29 from F2;
Column 10 from F1= Column 165 in F2;
and if value in column 8 from F2='3'
so that i can retrieve the value of column 7(in F2) which i need finally.
now can u help me.?
thanks
you need something like:
#!/usr/bin/perl
# get_col_values.pl
my $file1 = shift;
my $file2 = shift;
open (F1, '<',$file1) or die "Failed to read file $file1 : $! \n";
open (F2, '<',$file2) or die "Failed to read file $file2 : $! \n";
while (my $line_f1 = <F1>) {
my $line_f2 = <F2>;
my @fields_f1 = split (/\|/, $line_f1);
my @fields_f2 = split (/\|/, $line_f2);
if (($fields_f1[4] == $fields_f2[29]) and ($fields_f1[10] == $fields_f2[165]) and ($fields_f2[8] == 3)) {
print $fields_f1[4], " ", $fields_f1[5], " ", $fields_f1[8], " ", $fields_f1[10], " ", $fields_f2[29], " ", $fields_f2[165], " ", $fields_f2[7];
}
}
close (F1);
close (F2);
this perl script is untested, and needs a lot of improvements
hi yogesh,
i m having no idea about perl.
Cant we use simple unix commands in shell and awk to get the result?
Please help me with this.
Thanks in advance.