I've got a set of POSIX regular expressions*
^BEGIN:VCARD\r$ ^VERSION[^A-Z] ^FN[^A-Z] ^N[^A-Z] ^NICKNAME[^A-Z] ^EMAIL[^A-Z] ^X-\([A-Z-]*\) ^TEL[^A-Z] ^ADR[^A-Z] ^ORG[^A-Z] ^TITLE[^A-Z] ^BDAY[^A-Z] ^URL[^A-Z] ^ROLE[^A-Z] ^NOTE[^A-Z] ^END:VCARD\r$
and a file with lines which each match one of the regular expressions:
BEGIN:VCARD VERSION:3.0 N:Doe;Jane;;Ms; URL:http://janedoe.com/ EMAIL:[email protected] EMAIL:[email protected] BDAY:1970-01-01 X-JABBER:[email protected] X-ICQ:1234567890 END:VCARD
I'd like to sort these lines according to
- the line number of the regex match (so that lines starting with FN comes before lines starting with N),
- the match group (so that X-ABC comes before X-DEF)
Ideally, the other parts of the lines should not be sorted (so the sequence of lines which start with EMAIL should be left alone). The expected result should therefore be:
BEGIN:VCARD VERSION:3.0 N:Doe;Jane;;Ms; EMAIL:[email protected] EMAIL:[email protected] X-ICQ:1234567890 X-JABBER:jane.do[email protected] BDAY:1970-01-01 URL:http://janedoe.com/ END:VCARD
Is there an existing tool to do this?
* This is the sequence of vCard properties in a Gmail contacts export file.