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

Miriam English mim at miriam-english.org
Wed Nov 30 10:22:13 UTC 2011


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
>>
>>
>
>


-- 
If you don't have any failures then you're not trying hard enough.
  - Dr. Charles Elachi, director of NASA's Jet Propulsion Laboratory
-----
Website: http://miriam-english.org
Blogs:   http://miriam-e.dreamwidth.org
          http://miriam-e.livejournal.com


More information about the Techtalk mailing list