, , , - .
, , 1000 000 , 250 000 , , 4 , .
- , , ".txt":
#!/bin/bash
find . -name "*.txt" | while IFS= read a
do
grep -l banana "$a" | while IFS= read b
do
grep -l motorboat "$b" | while IFS= read c
do
grep -l "the white fox" "$c"
done
done
done
.
, awk 3 , , .
, , , . , " ", , , , . , , , .
, ".txt" , . , , , ( ) script :
use strict;
use warnings;
my %words;
my @files=<*.txt>;
foreach my $file (@files){
print "Loading: $file\n";
open my $fh, '<', $file or die "Could not open $file";
while (my $line = <$fh>) {
chomp $line;
foreach my $str (split /\s+/, $line) {
$words{$str}{$file}=1;
}
}
close($fh);
}
foreach my $str1 (keys %words) {
print "Word: \"$str1\" is in : ";
foreach my $str2 (keys $words{$str1}) {
print "$str2 ";
}
print "\n";
}
, , :
./go
Loading: a.txt
Loading: b.txt
Loading: c.txt
Loading: d.txt
Word: "the" is in : c.txt d.txt
Word: "motorboat" is in : b.txt d.txt
Word: "white" is in : c.txt d.txt
Word: "banana" is in : c.txt d.txt a.txt
Word: "fox" is in : c.txt d.txt