ocehb: (Default)
[personal profile] ocehb
имеется два файла, вытащить из них совпадающие слова.


проблема в определении "слова". пойдем по легкому пути: "\w+", и тогда:


# perl -e 'open A1,$ARGV[0]; open A2,$ARGV[1];
 while () { $hash{$&} = 1 while (m|\w+|g); }
 while () { $hash{$&}++ while (m|\w+|g); }
 foreach (grep { $hash{$_} > 1 && m|\D| } keys %hash) { printf "$_ "; }' /etc/passwd /etc/group
nobody rpm nscd nfsnobody postgres haldaemon games svn squid sshd bin mailnull postfix apache dbus xfs named mailman uucp rpc mysql news netdump gdm ldap smmsp rpcuser pcap gopher root ntp adm vcsa lp x ftp mail dovecot daemon exim webalizer
# 

или, если покрасивше:

#! perl
#

use strict;

open A1,$ARGV[0] or
        die sprintf "%s error: can't open '%s': %s\n",$0,$ARGV[0],$!;

open A2,$ARGV[1] or
        die sprintf "%s error: can't open '%s': %s\n",$0,$ARGV[1],$!;

my %hash;

while (<A1>) {
        $hash{$&} = 1 while (m|\w+|g);
}

while (<A2>) {
        $hash{$&}++ while (m|\w+|g);
}

close (A1); close (A2);

foreach (grep { $hash{$_} > 1 && m|\D| } keys %hash) {
        print "$_ ";
}

exit;



(deleted comment)
(deleted comment)
(deleted comment)

Profile

ocehb: (Default)
ocehb

January 2021

S M T W T F S
     12
345 6789
10111213141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 7th, 2026 12:30 pm
Powered by Dreamwidth Studios