Regular Expression Help
Matthew Seaman
m.seaman at infracaninophile.co.uk
Sun Nov 30 10:19:36 PST 2008
Drew Tomlinson wrote:
> I'm attempting to take an ldiff file and flip first/last name order.
> However I can not figure out how to match hyphenated last names. In
> vim, my current search/replace string is:
>
> %s/cn=\(\w\+\-*\) \(\w\+\),/cn=\2 \1,/gc
>
> This will match:
>
> cn=Smith Joe,
>
> and replace it with:
>
> cn=Joe Smith,
>
> But it will not match:
>
> cn=Smith-Brown Joe,
>
> nor replace it with:
>
> cn=Joe Smith-Brown,
>
> I've tried various incantations of escaping and quantifying yet I can
> 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 else
is forenames ...
% cat foo.txt
cn=Smith Joe,
cn=Smith-Brown Joe,
% perl -p -e 's/cn=([^ ,]+) ([^,]+),/cn=$2 $1,/' < foo.txt
cn=Joe Smith,
cn=Joe 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 precise
syntax. Perl, of course, just does the job for me.
Cheers,
Matthew
--
Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard
Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
Kent, CT11 9PW
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 258 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20081130/24e33b9a/signature.pgp
More information about the freebsd-questions
mailing list