File Manipulation

faithless1
faithless1 used Ask the Experts™
on
Hello,

I have a list of CSV (10+) files (i.e. A001.csv-A180), all of which contain data in column 13. I'm interested in doing the following:

1. Output  a list of records from file 1 which are present in other files along with the file names where these records are found.

Example of output for file 1. (A001_recurring.csv)

best day    A002.csv
best day    A003.csv
etc

Example of output for file 2. (A002_recurring.csv)

best day    A001.csv
best day    A003.csv
etc

Join all recurring files to create a main document.

Thank you
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2014
Top Expert 2015
Commented:
@ARGV=map"$_.csv",'A001'..'A180';
while( <> ){
    my $c=(split/,/)[12];                                                      
    ++$a{$ARGV}{$c};                                                            
    ++$s{$c}{$ARGV};                                                            
}                                                                              
for my $a( keys %a ){                                                          
    open STDOUT,">".($a=~/(\w+)/)[0]."_recurring.csv" or die $!;
    for my $c ( keys %{$a{$a}} ){
        print "$c\t$_\n" for sort grep{$_ ne $a}keys %{$s{$c}};
    }
}

Author

Commented:
Thanks,

The script only inserted file names into each file. Example below

cat A001.csv_recurring.csv
A002.csv


Files
cat A001.csv
store
store went
new
cat A002.csv
store
store went
new
random

Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial