Date: Sun, 30 Nov 2008 18:19:11 +0000 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: Drew Tomlinson <drew@mykitchentable.net> Cc: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: Regular Expression Help Message-ID: <4932D91F.5040804@infracaninophile.co.uk> In-Reply-To: <4932CA0D.8080109@mykitchentable.net> References: <4932CA0D.8080109@mykitchentable.net>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig108C1DB5D46C91DE784207F4 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Drew Tomlinson wrote: > I'm attempting to take an ldiff file and flip first/last name order. =20 > However I can not figure out how to match hyphenated last names. In=20 > vim, my current search/replace string is: >=20 > %s/cn=3D\(\w\+\-*\) \(\w\+\),/cn=3D\2 \1,/gc >=20 > This will match: >=20 > cn=3DSmith Joe, >=20 > and replace it with: >=20 > cn=3DJoe Smith, >=20 > But it will not match: >=20 > cn=3DSmith-Brown Joe, >=20 > nor replace it with: >=20 > cn=3DJoe Smith-Brown, >=20 > I've tried various incantations of escaping and quantifying yet I can=20 > not figure out how to do what I want. Well, assuming that none of the surnames contain ',' and that the first '= ' (space) is always the delimiter between the surname and that anything els= e is forenames ...=20 % cat foo.txt=20 cn=3DSmith Joe, cn=3DSmith-Brown Joe, % perl -p -e 's/cn=3D([^ ,]+) ([^,]+),/cn=3D$2 $1,/' < foo.txt=20 cn=3DJoe Smith, cn=3DJoe Smith-Brown, ie. you need a s/// command that understands negated character classes. = I think sed(1) and vi(1) will do that, but I haven't time to look up the pr= ecise syntax. Perl, of course, just does the job for me. Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW --------------enig108C1DB5D46C91DE784207F4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEAREIAAYFAkky2S8ACgkQ8Mjk52CukIxj7ACfSDDR6rlLZD2jrcqchD3wZn76 VvUAmwWmew53xvsyMmB84SO2NhWVtBOv =+rGm -----END PGP SIGNATURE----- --------------enig108C1DB5D46C91DE784207F4--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4932D91F.5040804>