in reply to Filtering Output from two files
I am not sure if this is homework or not? If so, you should tell us.
However, I will give you some actual code.
I process text files frequently - Perl is great at this.
Skipping blank lines in the input is a normal "reflex reaction" by me and I show a common way to do that.
Update: I read more of the posts in this thread. If file 1 is 700K lines, this should work just fine on a modern computer. My ancient (now dead) XP laptop would have had some issues with a hash of that size due to memory issues. A modern 64 bit computer won't even blink. If there are issues, there are ways to reduce the memory footprint. Let's not go there unless it is necessary.#!/usr/bin/perl use warnings; use strict; use Inline::Files; my %File1Hash; while (my $line = <FILE1>) { next if $line =~ /^\s*$/; # skip blank lines $line =~ s/\s*$//; # remove all trailing space, # including the line ending $File1Hash{$line}++; } while (my $line = <FILE2>) { next if $line =~ /^\s*$/; # skip blank lines my ($id) = split /\|/,$line; # get the first field print $line if exists $File1Hash{$id}; } =Prints COA213345|a|b|c| COA213345|a|b|c| =cut __FILE1__ COA213345 COA213345 COA213445 DOB213345 EOA213345 __FILE2__ COA213345|a|b|c| COA213345|a|b|c| LOA213345|a|b|c| kOB213345|a|b|c| LOA213345|a|b|c|
|
|---|