[Techtalk] script to change uppercase to title case in OFX/QFX -- solved

Carla Schroder carla at bratgrrl.com
Wed Dec 28 04:40:05 UTC 2011


I'm baaaack....

I forgot to followup. Thanks to Akkana it works. John, I haven't touched Emacs 
in so long it looks like a foreign country :)

This is what I use:

$ cat filename-in.ofx |  sed '/\(NAME\|MEMO\)/s/\([ >][A-Z]\)\([A-
Z]*\)/\1\L\2/g'   > filename-out.ofx

It works like a charm, changing this:
<FITID>2650

<NAME>WITHDRAW
<MEMO>INS 877.665.7563SELMAN&CO.111222

To this:

<FITID>2650

<NAME>Withdraw
<MEMO>Ins 877.665.7563SELMAN&CO.111222

Miriam's regexp-- sed '/<NAME>\|<MEMO>/s/\([A-Z]*\)\( \|$\)/\L\u\1\2/g'  --is 
a little bit different and does something different to the NAME field. When there 
is a single word in the name field it remains in caps:

<NAME>WITHDRAW
							
When there is more than one word it changes only the first word:

<NAME>Share WITHDRAW

So something interesting is happening there I haven't tried to figure out yet. 

Thanks everyone, amazing you are!

Carla

> Amazing how you can look at something again and see it quite differently.
> 
> sed '/<NAME>\|<MEMO>/s/\([A-Z]*\)\( \|$\)/\L\u\1\2/g'
> 
> work only on lines containing "<NAME>" or "<MEMO>"
> do a substitution
>     looking for for strings of capital letters ending in
>     either a space or the end of line
> and change to
>     the string translated to all lowercase,
>     but with the first letter uppercase
> 
> Wow!
> 
> Miriam English wrote:
> > Hi Carla,
> > 
> > A quick reply because I have to rush out to an appointment shortly...
> > 
> > sed can translate stuff, but it is a royal pain.
> > For instance the following will translate the first word after the NAME
> > tag, leaving the first character as uppercase
> > sed 's/\(<NAME>\)\([A-Z]*\)/\1\L\u\2/g'
> > 
> > \U the following text becomes uppercase
> > \u only the first character of following text becomes uppercase.
> > \L the following text becomes lowercase.
> > \l (letter ell) only the first character of following text becomes lower
> > case.
> > 
> > You can probably generalise this further. My instinct is that if you
> > want anything more complex than what you said in the post that I'd opt
> > to use awk. In fact awk might even be better for this anyway. :)
> > 
> > Gotta go, hope this helps,
> > 
> > - Miriam
> > 
> > Carla Schroder wrote:
> >> It is MUCH too quiet here. So here is a little problem for you fine
> >> brainiacs.
> >> I import OFX/QFX files from my bank accounts into GnuCash, a nice time
> >> saver.
> >> BUT. It is all uppercase, so it's like GnuCash is shouting at me,
> >> which makes
> >> me sad. I've been trying to figure out a nice one-liner or script to
> >> convert
> >> selected fields to title case, and so far have failed utterly. QFX is
> >> Quicken's
> >> proprietary "enhancement" to the open OFX format; it includes some
> >> secret magic somewhere to force institutions to pay royalties. Nice,
> >> eh? But I digress. Both are a form of SGML, and this is what it looks
> >> like:
> >> 
> >> <STMTTRN>
> >> <TRNTYPE>DEBIT
> >> <DTPOSTED>20111125000000[-5:EST]
> >> <TRNAMT>-22.71
> >> <FITID>****
> >> 
> >> <NAME>CHESTERS THRIFTWAY JOHN
> >> <MEMO>CHESTERS THRIFTWAY JOHN DAY OR 11-25-11 330346
> >> </STMTTRN>
> >> 
> >> <STMTTRN><TRNTYPE>DEBIT
> >> <DTPOSTED>20111125000000[-5:EST]
> >> <TRNAMT>-4.56
> >> <FITID>***
> >> 
> >> <NAME>USPS 4058720860963919 MOUNT
> >> <MEMO>USPS 4058720860963919 MOUNT VERNON OR 11-24-11 910453
> >> </STMTTRN>
> >> 
> >> 
> >> I want the NAME and MEMO fields in title case. The tags need to be in
> >> uppercase; I don't know if this part of the spec or a limitation in
> >> GnuCash.
> >> Is this too much to ask? So much happiness it would bring. I have tried
> >> various things myself and not figured out the magic that selects only
> >> the NAME
> >> and MEMO data without changing tags or other data fields.
> >> 
> >> thanks :)
> >> 
> >> Carla
> >> 
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> Carla Schroder, ace Linux guru and howto author
> >> 541-932-4817 PT
> >> carla at tuxcomputing.com
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> _______________________________________________
> >> Techtalk mailing list
> >> Techtalk at linuxchix.org
> >> http://mailman.linuxchix.org/mailman/listinfo/techtalk


More information about the Techtalk mailing list