From owner-freebsd-questions@FreeBSD.ORG Thu Sep 13 19:35:57 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 E6E9416A476 for ; Thu, 13 Sep 2007 19:35:57 +0000 (UTC) (envelope-from kurt.buff@gmail.com) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.170]) by mx1.freebsd.org (Postfix) with ESMTP id 7015913C468 for ; Thu, 13 Sep 2007 19:35:57 +0000 (UTC) (envelope-from kurt.buff@gmail.com) Received: by ug-out-1314.google.com with SMTP id a2so497255ugf for ; Thu, 13 Sep 2007 12:35:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=fvOw9oyQ0s+Je08T0kPJdbUX2cRDFxHZun6kH0V2O+8=; b=ZaGWgxGgAW+JHe94WaBm0NG0AYNPvEx+LXr+jCzFAFXq8sLTnOjZkf68MSVOyFInAeJ+Val8r/WzENudkEhcjZ7iP9of0Q8UahrALGWRBFMUtKs0g1UD2ZdAsU7KXj+14qvURUWw6W0sEW8rBtecIihWwMV1SNwb59owPf9zqOs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=l0ZxDa9SJsU8BsMCSCL0Dgp11kVPLJb6Dan2ug1ZA3FB56RW0h/aH57qG0cyg8Hq/3L6FeQUEMz3S4ZnUg60mW73N9ZmDjnOLvddaUvQfM378FRFACBS5EkL7lzLZrLmTmMIOPDuCavylOBsZeUysAz9ivPr98XWDX2dYkBhTYA= Received: by 10.143.16.9 with SMTP id t9mr231076wfi.1189712153968; Thu, 13 Sep 2007 12:35:53 -0700 (PDT) Received: by 10.142.78.21 with HTTP; Thu, 13 Sep 2007 12:35:53 -0700 (PDT) Message-ID: Date: Thu, 13 Sep 2007 12:35:53 -0700 From: "Kurt Buff" To: freebsd-questions@freebsd.org In-Reply-To: <20070913183504.GC11683@slackbox.xs4all.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20070913183504.GC11683@slackbox.xs4all.nl> 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 19:35:58 -0000 On 9/13/07, Roland Smith wrote: > 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. > > > > 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. > > > > Example: > > > > kurt.buff@gmail.com NO > > kurt.buff@gmail.com OK > > > > 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. > > > > 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. > > > > I don't have the perl skills, though that would be ideal. > > > > 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) = each(%names)) { > if ($count == 1) { > # print unique names. > print $name, "\n"; > } > } > > > Roland > -- > 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) I can follow the logic in that. I'll definitely try incorporating that. Thanks!