in reply to match two files
This will probably shorten the running time but I don't have your data to test it on, so good luck.
#!/usr/bin/perl use warnings; use strict; use Fcntl ':seek'; open my $CSV, '<', 'donor_82_01.csv' or die "Cannot open 'donor_82_01. +csv' because: $!"; my $pos = tell $CSV; my %csv_data; while ( <$CSV> ) { my ( $first ) = split /,+/; push @{ $csv_data{ $first } }, $pos; $pos = tell $CSV; } open my $TAB, '<', 'tmp12' or die "Cannot open 'tmp12' because: $!"; open my $OUT, '>', 'tmp12_02' or die "Cannot open 'tmp12_02' because: +$!"; while ( <$TAB> ) { my ( $first, $second ) = split /\t+/; next unless exists $csv_data{ $second }; for my $pos ( @{ $csv_data{ $second } } ) { seek $CSV, $pos, SEEK_SET or die "Cannot seek on 'dono +r_82_01.csv' because: $!"; print $OUT "$first,", scalar <$CSV>; } } close $CSV; close $TAB; close $OUT;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: match two files
by yueli711 (Sexton) on Jun 04, 2020 at 05:02 UTC | |
by jwkrahn (Abbot) on Jun 04, 2020 at 18:26 UTC | |
by yueli711 (Sexton) on Jun 05, 2020 at 02:09 UTC | |
by jwkrahn (Abbot) on Jun 05, 2020 at 23:44 UTC | |
by yueli711 (Sexton) on Jun 06, 2020 at 01:56 UTC |