Присоединяйтесь к двум файлам на основе общего поля

Если у вас есть GNU tools:

find -maxdepth 1 -type f -printf '%s %p\0' | 
  awk -v RS='\0' '{a[$0]=$1;s+=$1;}
                  END{m=s/NR; for(i in a){if(a[i]>=m){print i}}}' 

А если нет:

perl -le 'opendir(D,"."); @F=readdir(D); @files=grep{-f $_}@F; 
    for (@files){$s= -s $_; $t+=$s; $f{$_}=$s} 
    print join "\n",grep{$f{$_}>=$t/scalar(@files)}@files' 

Что можно расширить до:

#!/usr/bin/perl 

## Open the current directory as D
opendir(D,".");
## Read the contents of D into @F
@F=readdir(D);
## Collect only the files, no dirs etc. 
@files=grep{-f $_}@F;
## For each file, as $_
for (@files){
    ## Get the size
    $s= -s $_;
    ## Add the size to the total
    $t+=$s;
    ## Save the size in the hash %f whose keys are the file names
    $f{$_}=$s
}
## Get all files whose size is greater than the average
my @wanted=grep{$f{$_}>=$t/scalar(@files)}@files;
## Print the elements of the array @wanted with a newline after each of them
print join "\n", @wanted ;
print "\n";
4
10.01.2019, 21:00
1 ответ


с Миллеромhttp://johnkerl.org/miller/doc/reference.htmlкоманда

mlr --csv --implicit-csv-header --headerless-csv-output --fs ":" join --ul -l 4 -r 1 -j 4 --lp l --rp r -f file2.csv file1.csv

А у вас есть

C01:R001:07/04/15:123.45:Nancy:Jones:njones@abc.com
C02:R005:11/27/16:58.00:Barbara:Madison:bmadison@bcd.com
C03:R002:12/20/15:167.50:Tim:Adams:tadams@cde.com
C03:R005:09/15/16:36.50:Tim:Adams:tadams@cde.com
C05:R006:02/28/17:72.98:John:Polk:jpolk@efg.com
C06:R003:03/14/16:298.00:Paula:Jacobs:pjacobs@fgh.com
0
27.01.2020, 20:59

Теги

Похожие вопросы