in reply to Re^4: match two files
in thread match two files
This should do it:
#!/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: $!"; open my $TAB, '<', 'tmp12' or die "Cannot open 'tmp12' because: $!"; open my $OUT, '>', 'tmp12_01' or die "Cannot open 'tmp12_01' because: +$!"; my $pos = tell $CSV; my %csv_data; while ( <$CSV> ) { my ( $first ) = split /,+/; print $OUT ",$_" unless length $first; push @{ $csv_data{ $first } }, $pos; $pos = tell $CSV; } while ( <$TAB> ) { my ( $first, $second ) = split or next; next unless exists $csv_data{ $second }; for my $pos ( @{ $csv_data{ $second } } ) { seek $CSV, $pos, SEEK_SET or die "Cannot seek on 'donor_82_01. +csv' because: $!"; print $OUT "$first,", scalar <$CSV>; } } close $CSV; close $TAB; close $OUT;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: match two files
by yueli711 (Sexton) on Jun 06, 2020 at 01:56 UTC |