(no subject)
Apr. 25th, 2006 02:01 pmимеется два файла, вытащить из них совпадающие слова.
проблема в определении "слова". пойдем по легкому пути: "\w+", и тогда:
или, если покрасивше:
проблема в определении "слова". пойдем по легкому пути: "\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;
no subject
Date: 2006-04-25 12:15 pm (UTC)задача сформулирована тут.
no subject
Date: 2006-04-25 12:23 pm (UTC)no subject
Date: 2006-04-25 12:25 pm (UTC)no subject
Date: 2006-04-25 12:26 pm (UTC)no subject
Date: 2006-04-25 12:29 pm (UTC)#!/usr/bin/perl -ln $i++ if(eof); $hash[$i]{$&} = 1 while (m|\w+|g); END { for(keys %{$hash[0]}) { print if($hash[1]{$_}) } }no subject
Date: 2006-04-25 12:39 pm (UTC)perl проникает прямо в моск
Date: 2006-04-25 01:12 pm (UTC)#!/usr/bin/perl -n0aF/\W+|\d+/
$i++;
$h{$_} |= $i for(@F);
END{
for (grep { $h{$_} == 3 } keys %h) { print "$_ " }
}
no subject
Date: 2006-04-25 01:14 pm (UTC)test.pl:
a.pl:
j.pl:
Re: perl проникает прямо в моск
Date: 2006-04-25 01:20 pm (UTC)кого волнует производительность?
Date: 2006-04-25 01:22 pm (UTC)no subject
Date: 2006-07-28 03:16 pm (UTC)words() { sed 's/[^a-z]/\n/g' ${1+"$@"} |grep .. |sort -u; }
comm -12 <(words "$1") <(words "$2")
no subject
Date: 2006-07-28 03:22 pm (UTC)$ grep -Po '\w+' /etc/passwd |head
root
x
0
0
System
Administrator
root
bin
bash
bin
$
Правда не каждый греп такое сможет сделать.
no subject
Date: 2006-07-29 08:45 pm (UTC)