From owner-freebsd-questions@FreeBSD.ORG Thu Sep 13 18:35:07 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AC58E16A420 for ; Thu, 13 Sep 2007 18:35:07 +0000 (UTC) (envelope-from rsmith@xs4all.nl) Received: from smtp-vbr11.xs4all.nl (smtp-vbr11.xs4all.nl [194.109.24.31]) by mx1.freebsd.org (Postfix) with ESMTP id 3587813C442 for ; Thu, 13 Sep 2007 18:35:06 +0000 (UTC) (envelope-from rsmith@xs4all.nl) Received: from slackbox.xs4all.nl (slackbox.xs4all.nl [213.84.242.160]) by smtp-vbr11.xs4all.nl (8.13.8/8.13.8) with ESMTP id l8DIZ5xe020497; Thu, 13 Sep 2007 20:35:05 +0200 (CEST) (envelope-from rsmith@xs4all.nl) Received: by slackbox.xs4all.nl (Postfix, from userid 1001) id E7B70B862; Thu, 13 Sep 2007 20:35:04 +0200 (CEST) Date: Thu, 13 Sep 2007 20:35:04 +0200 From: Roland Smith To: Kurt Buff Message-ID: <20070913183504.GC11683@slackbox.xs4all.nl> Mail-Followup-To: Kurt Buff , freebsd-questions@freebsd.org References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="+xNpyl7Qekk2NvDX" Content-Disposition: inline In-Reply-To: X-GPG-Fingerprint: 1A2B 477F 9970 BA3C 2914 B7CE 1277 EFB0 C321 A725 X-GPG-Key: http://www.xs4all.nl/~rsmith/pubkey.txt X-GPG-Notice: If this message is not signed, don't assume I sent it! User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: by XS4ALL Virus Scanner Cc: freebsd-questions@freebsd.org Subject: Re: Scripting question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Sep 2007 18:35:07 -0000 --+xNpyl7Qekk2NvDX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 13, 2007 at 10:16:40AM -0700, Kurt Buff wrote: > I'm trying to do some text file manipulation, and it's driving me nuts. >=20 > I've got a sorted file of SMTP addresses, and want to eliminate the > lines that are the same up to a space character within the line. >=20 > Example: >=20 > kurt.buff@gmail.com NO > kurt.buff@gmail.com OK >=20 > The above lines *both* need to be eliminated from output - I don't > want the first or second of them, I want them both gone. >=20 > I've looked at sort and uniq, and I've googled a fair bit but can't > seem to find anything that would do this. >=20 > I don't have the perl skills, though that would be ideal. >=20 > Any help out there? #!/usr/bin/perl while (<>) { # Assuming no whitespace in addresses; kill everything after the first = space s/ .*$//; # Store the name & count in a hash $names{$_}++; } # Go over the hash while (($name,$count) =3D each(%names)) { if ($count =3D=3D 1) { # print unique names. print $name, "\n"; } } Roland --=20 R.F.Smith http://www.xs4all.nl/~rsmith/ [plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated] pgp: 1A2B 477F 9970 BA3C 2914 B7CE 1277 EFB0 C321 A725 (KeyID: C321A725) --+xNpyl7Qekk2NvDX Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) iD8DBQFG6YLYEnfvsMMhpyURAiv6AJsGXozQdA5OcHngIRYEcL+gPe6VmQCfZZlq G5zqSImgD3wp09IqEBj9v4s= =QW1X -----END PGP SIGNATURE----- --+xNpyl7Qekk2NvDX--