in reply to extract line
G'day lallison,
Welcome to the monastery.
This code does what you describe as being wanted:
$ perl -Mstrict -Mwarnings -e ' use autodie; use Tie::File; my $re = qr{^((\d+).+$)}s; my %data_for_part; open my $f1, "<", "pm_1045452_file1.txt"; while (<$f1>) { /$re/; $data_for_part{$2} = $1; } close $f1; tie my @file2, "Tie::File", "pm_1045452_file2.txt"; print $data_for_part{$_} for @file2; untie @file2; ' 3478749:AA:1D:AAA:DescriptionsY:C:2 3633731:AA:3E:AAA:DescriptionsZ:C:2
I made a minor change to "File1" to show different Descriptions:
$ cat pm_1045452_file1.txt 3478748:AA:1D:AAA:DescriptionsX:C:2 3478749:AA:1D:AAA:DescriptionsY:C:2 3633731:AA:3E:AAA:DescriptionsZ:C:2
"File2" data is as you show it:
$ cat pm_1045452_file2.txt 3478749 3633731
Notes:
"This file has over a million lines and is running very slow."
Given that you've been provided with a number of solutions, use Benchmark to determine which works best for you. (That module also comes standard with Perl.)
[Aside: The code you posted is difficult to read due to the <code> tag issue. You appear to have made an effort but were unsuccessful: see Writeup Formatting Tips for how, where and why to do it.]
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: extract line
by lallison (Novice) on Jul 21, 2013 at 17:46 UTC | |
by kcott (Archbishop) on Jul 22, 2013 at 09:09 UTC | |
|
Re^2: extract line
by lallison (Novice) on Jul 21, 2013 at 17:28 UTC | |
by kcott (Archbishop) on Jul 22, 2013 at 08:50 UTC |