Uma solução usando Perl :
Conteúdo de entity.txt :
$ cat entity.txt
624197
624252
624264
624276
624280
624309
624317
Conteúdo do reference.txt :
$ cat reference.txt
624252|624346
624264|1070122
624264|624346
624276|624588
624280|624346
624280|624582
624298|624588
624319|333008
624330|624588
Conteúdo do script Perl:
$ cat script.pl
use warnings;
use strict;
## Check arguments.
@ARGV == 2 or die qq[Usage: perl $0 <entity-file> <reference-file>\n];
## File in process.
my $process_file = 1;
## Hash to save entities.
my %entity;
while ( <> ) {
## Process file of entities. Remove leading and trailing spaces, and save the
## number to a hash.
if ( $process_file == 1 ) {
s/\A\s*//;
s/\s*\z//;
if ( defined $_ ) { $entity{ $_ } = 1 }
next;
}
## Process file of references. Get first field and search it in the hash.
## If found, print the line.
my @f = split /\|/, $_, 2;
if ( exists $entity{ $f[0] } ) {
print;
}
} continue {
## Increment number when end processing first file.
if ( eof ) { ++$process_file }
}
Executando o script sem argumentos:
$ perl script.pl
Usage: perl script.pl <entity-file> <reference-file>
Executando o script com argumentos e resultado:
$ perl script.pl entity.txt reference.txt
624252|624346
624264|1070122
624264|624346
624276|624588
624280|624346
624280|624582