in reply to Re^4: Search a file with ids from another file
in thread Search a file with ids from another file
There are probably 50 or 60 ids.
Few enough!
The next line cannot match the one id. I should have posted a copy of that as well but basically 1 id will create 2 lines in the logfile and it is that second line I am trying to get at.
How 'bout the other question? Well, taking one assumption, one way to do what you're after may be along the lines of the following:
#!/usr/bin/perl use strict; use warnings; die "Usage: $0 <id_file> [<files>]\n" unless @ARGV; my %id_hit=map { substr($_, 0, 6) => 1 } do { my $idfile=shift; open my $fh, '<', $idfile or die "Can't open `$idfile': $!\n"; <$idfile>; }; while (<>) { if (/([A-Z]\d{5})/ and $id_hit{$1}) { defined(my $next=<>) or die "No 'next' line in `$ARGV' at line $.\n"; print $next; } } __END__
|
|---|