Date: Thu, 13 Sep 2007 20:35:04 +0200 From: Roland Smith <rsmith@xs4all.nl> To: Kurt Buff <kurt.buff@gmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: Scripting question Message-ID: <20070913183504.GC11683@slackbox.xs4all.nl> In-Reply-To: <a9f4a3860709131016w54c12b6fy94fc2b0f286aea3d@mail.gmail.com> References: <a9f4a3860709131016w54c12b6fy94fc2b0f286aea3d@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--+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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070913183504.GC11683>
