in reply to Comparing files and and elements of arrays
#!/usr/bin/perl my $filename02 = "unapproved.txt"; my $filename03 = "approved.txt"; my $filename04 = "compared.txt"; open(UNAPPROVED,"+<$filename02") || die "Can't open file $filename02"; + # open destination text file open(APPROVED,"+<$filename03") || die "Can't open file $filename03"; # + open destination text file open(COMPARED,"+>$filename04") || die "Can't open file $filename04"; # + open destination text file my @unapprovedline; my @approvedline; @approvedall = <APPROVED>; @unapprovedall = <UNAPPROVED>; close APPROVED; close UNAPPROVED; $numoflines01 = @unapprovedall; $numoflines02 = @approvedall; for ($x = 0; $x < $numoflines01; $x++) { $line01 = @unapprovedall[$x]; @unapprovedline = split (/\"/, $line01); for ($y = 0; $y < $numoflines02; $y++) { $line02 = @approvedall[$y]; @approvedline = split (/\"/, $line02); $uleft = @unapprovedline[5]; $aleft = @approvedline[5]; $uright = @unapprovedline[7]; $aright = @approvedline[7]; $uping = @unapprovedline[13]; $aping = @approvedline[13]; if ($uping eq $aping && $uleft eq $aleft && $uright eq $aright +) { print COMPARED "\"", @approvedline[1], "\"", "\t"; print COMPARED "\"", @approvedline[3], "\"", "\t"; print COMPARED "\"", @approvedline[5], "\"", "\t"; print COMPARED "\"", @approvedline[7], "\"", "\t"; print COMPARED "\"", "@approvedline[9] @unapprovedline[1], +", "\"", "\t"; print COMPARED "\"", @approvedline[11], "\"", "\t"; print COMPARED "\"", @approvedline[13], "\"", "\t", "\n"; } else { print COMPARED "\"", @unapprovedline[1], "\"", "\t"; print COMPARED "\"", @unapprovedline[3], "\"", "\t"; print COMPARED "\"", @unapprovedline[5], "\"", "\t"; print COMPARED "\"", @unapprovedline[7], "\"", "\t"; print COMPARED "\"", @unapprovedline[9], "\"", "\t"; print COMPARED "\"", @unapprovedline[11], "\"", "\t"; print COMPARED "\"", @unapprovedline[13], "\"", "\t", "\n" +; } } } close COMPARED; # delete UNAPPROVED
Heres the file that is produced from the above code...
"A1000000" "" "DB50F-LEFT" "DB50F-RIGHT" "" "" + "L1:R1 L2:R2 L3:R3 L4:R4 L5:R5 L6:R6 L7:R7" "M50DFFU" "" "DB50F-LEFT" "DB50F-RIGHT" " 1000000," + "" "L1:R1 L2:R2 L3:R3 L4:R4 L5:R5 L6:R6 L7:R7" "A1000000" "" "DB50F-LEFT" "DB50F-RIGHT" "" "" + "L1:R1 L2:R2 L3:R3 L4:R4 L5:R5 L6:R6 L7:R7" "A1000000" "" "DB50F-LEFT" "DB50F-RIGHT" "" "" + "L1:R1 L2:R2 L3:R3 L4:R4 L5:R5 L6:R6 L7:R7" "A1000000" "" "DB50F-LEFT" "DB50F-RIGHT" "" "" + "L1:R1 L2:R2 L3:R3 L4:R4 L5:R5 L6:R6 L7:R7" "P000001" "" "DB9F-LEFT" "DB9F-RIGHT" " 5000001," " +" "L1:R1 L2:R2 L6:R6" "A5000001" "" "DB9F-LEFT" "DB9F-RIGHT" "" "" + "L1:R1 L2:R2 L6:R6" "A5000001" "" "DB9F-LEFT" "DB9F-RIGHT" "" "" + "L1:R1 L2:R2 L6:R6" "A5000001" "" "DB9F-LEFT" "DB9F-RIGHT" "" "" + "L1:R1 L2:R2 L6:R6" "A5000001" "" "DB9F-LEFT" "DB9F-RIGHT" "" "" + "L1:R1 L2:R2 L6:R6" "A9999999" "" "DB00F-LEFT" "DB00F-RIGHT" "" "" + "L1:R1 L3:R3 L4:R4 L6:R6" "A9999999" "" "DB00F-LEFT" "DB00F-RIGHT" "" "" + "L1:R1 L3:R3 L4:R4 L6:R6" "A9999999" "" "DB00F-LEFT" "DB00F-RIGHT" "" "" + "L1:R1 L3:R3 L4:R4 L6:R6" "A9999999" "" "DB00F-LEFT" "DB00F-RIGHT" "" "" + "L1:R1 L3:R3 L4:R4 L6:R6" "A9999999" "" "DB00F-LEFT" "DB00F-RIGHT" "" "" + "L1:R1 L3:R3 L4:R4 L6:R6"
And this is what i im trying to do with the results produced above...again this is probably a very long way of solving this problem but i cant really think of any other way to do it as my perl knowledge is limited
# for each line, get the part no., compare to contents of # the notes field on every other line, if it is in the # notes field, delete the line otherwise leave and move on # to the next line. Finally delete all dupes and merge the # list with the approved.txt open(COMPARED,"+<$filename04") || die "Can't open file $filename04"; # + open destination text file @comparedall = <COMPARED>; $numoflines03 = @comparedall; for ($a = 0; $a < $numoflines03; $a++) { $line03 = @comparedall[$a]; @comparedline = split (/\"/, $line03); $part = @comparedline[1]; $notes = @comparedline[9]; @notes = split (/\,/, $notes); $numofnotes = @notes; for ($b = 0; $b <= $numofnotes; $b++) { $notescontent = @notes[$b]; print $notescontent, "\n"; if ($part eq $notescontent) { print "hello"; } } }
Thanks for everyones help, Steve.
|
|---|