converting qfx files to qif

Peter Dolloff dolloffp@yahoo.ca
Sat, 21 Apr 2001 10:16:11 -0400 (EDT)


Hi

If you're like me, your banking institutions don't
even offer qif files as a download, meaning you have
to enter everything into gnucash manually.  Yuck.  So,
I came up with some simple awk scripts to very crudely
convert qfx files to qif.  These scripts work well
with my accounts, which are simple checking accounts. 
You may have to edit them if you are importing
different accounts.

Here's the first script.  This one is for qfx files
that don't have each tag on a seperate line.  This
script separates all tags:

#!/usr/bin/mawk -f
// {
        gsub("<","\n<",$0)
        print $0
}

Very simple, yes?  You can use it like this (if the
script was called ofx2qif1 and the downloaded qfx file
was sample.qfx)

cat sample.qfx |./ofx2qif1 > new.qfx

Now, once you have run that script (you may not have
to if the tags are already on different lines), you
can run the next script, that extracts transaction
data and puts it into qif form (save the script as
ofx2qif2):

#!/usr/bin/mawk -f
/OFXHEADER/ {
	print "!Type:Bank"
}
/<DTPOSTED>/ { 
	sub(/<DTPOSTED>/,"",$0)
	sub(/^ */,"",$0)

printf("D%s/%s/%s\n",substr($0,5,2),substr($0,7,2),substr($0,3,2))
}
/<MEMO>/ {
	sub(/<MEMO>/,"P", $0)
	sub(/^ */,"",$0)
	sub(/\&amp\;/,"\&",$0)
	gsub(/\;/," ",$0)
	print $0
}
/<NAME>/ {
	sub(/<NAME>/,"M", $0)
	sub(/^ */,"",$0)
	sub(/\&amp\;/,"\&",$0)
	print $0
}
/<TRNAMT>/ {
	sub(/<TRNAMT>/,"T", $0)
	sub(/^ */,"",$0)
	print $0
}
/<\/STMTTRN>/ {
	sub(/<\/STMTTRN>/,"^", $0)
	sub(/^ */,"",$0)
	print $0
}

Use it as follows:

cat new.qfx|./ofx2qif2 > new.qif

Now you have a file (new.qif) that you can import into
gnucash.  Cool, eh?

MODIFICATIONS

You may have to play with the ofx2qif2 script.  I've
noticed that one of my financial institutions puts the
more descriptive info for each transaction into the
<MEMO> tag, while another uses <NAME>, so you may have
to edit those two rules.  Otherwise, they seem to work
well.  Let me know if you have any problems.

Peter Dolloff

_______________________________________________________
Do You Yahoo!?
Get your free @yahoo.ca address at http://mail.yahoo.ca