how to edit ofx file with sed editor? Replace Copy FITID

Chris Good chris.good at ozemail.com.au
Wed Oct 5 20:45:59 EDT 2016


> Message: 8
> Date: Mon, 3 Oct 2016 17:31:07 -0700 (PDT)
> From: LinforPros <linforpros at gmail.com>
> To: gnucash-user at gnucash.org
> Subject: RE: how to edit ofx file with sed editor? Replace Copy FITID
> Message-ID: <1475541067708-4686893.post at n4.nabble.com>
> Content-Type: text/plain; charset=us-ascii
> 
> Chris,
> I think I found the problem.
> The removal of "^" from your script seems to work.
> 
> <FITID>20160902000000[-6:CST]*-27.68*13**POS DEB 2022 09/01/16
> 00077336 KUM GO #0633 1400 N MINNESOTA A <NAME>POS DEB 2022
> 09/01/16 00077336 KUM  GO #0633 1400 N MINNESOTA A
> 
> The script looks looks like this now:
> 
> $ cat awkconvert_gwb.awk
> /<STMTTRN>/ {
> 	name=""
> }
> /<FITID>/ {
> 	idx=index($0, "**")
> 	if (idx > 0) {
> 		name=substr($0, idx+2)
> 	}
> }
> /<NAME>/ {
> 	if (length(name) > 0) {
> 		print "<NAME>" name
> 		next
> 	}
> }
> { print }
> 
> 
> Do you think it will be safe to use it without those ^ ?
> 
> regards
> Lin
> 
> 
> 
> -----
> regards
> Lin
> --
> View this message in context: http://gnucash.1415818.n4.nabble.com/RE-
> how-to-edit-ofx-file-with-sed-editor-Replace-Copy-FITID-
> tp4686890p4686893.html
> Sent from the GnuCash - User mailing list archive at Nabble.com.
> 

Hi Lin,

Well done narrowing down the problem.
Looks like your version of awk (gawk) does not implement using ^ to match
start of string like my awk (Ubuntu 16.04 mawk 1.3.3 Nov 1996).

Just for interest, what OS and version are you using?

Your modified version should be OK except in the extremely unlikely case an
OFX tag appears somewhere in the data other than at the start of a line.
Please try the following which specifically checks for the ofx tags at the
start of the line and hopefully will work in gawk... It works in mawk but I
haven't tested in gawk.

(index($1, "<STMTTRN>") == 1) {
 	name=""
}
(index($1, "<FITID>") == 1) {
	idx=index($0, "**")
	if (idx > 0) {
		name=substr($0, idx+2)
	}
}
(index($1, "<NAME>") == 1) {
	if (length(name) > 0) {
		print "<NAME>" name
		next
	}
}
{ print }

I have again attached above in ofx.txt in case mail alters any of the
special characters.

Regards, Chris Good
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ofx.txt
URL: <http://lists.gnucash.org/pipermail/gnucash-user/attachments/20161006/ae3a8184/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4817 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-user/attachments/20161006/ae3a8184/attachment.p7s>


More information about the gnucash-user mailing list