Shell script not working -> change contents of OFX file

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

I'm trying to change the contents of a OFX file (bank statement) using one of the following shell scripts (both achieve the same result):

Option 1:
Code: Select all
sed -i.bak '/<TRNAMT">/s//&-/; s/--/-/' $1


Option 2:
Code: Select all
perl -pe 's/^(<TRNAMT>)(-?\d+\.\d+)$/sprintf "%s%.2f", $1, -$2/e' $1


I ran both on Terminal replacing $1 with the file name and they work, so I'm doing something wrong in Hazel.
I really have no experience at all with Unix commands, I got help on a Unix forum to get those scripts.

Do I have to add a path? Or something before or after the commands?

The Hazel rule is:
IF: file extension is ofx
DO THE FOLLOWING: Run Shell Script

In case it helps, the scripts reverse the sign of numbers in specific lines, so that a positive number becomes negative and vice versa. The lines always starts with <TRNAMT> followed by the amount, example below, in red:

<STMTTRN>
<TRNTYPE>DEBIT
<DTPOSTED>20151127000001[-3:GMT]
<TRNAMT>-8.77
<FITID>667800007
<CHECKNUM>667800007
<MEMO>PAYPAL
</STMTTRN>
rpedro
 
Posts: 29
Joined: Wed Jun 27, 2012 6:17 am

You should enclose the $1 in double-quotes, in case the path has characters like spaces in them. See if that fixes things.
Mr_Noodle
Site Admin
 
Posts: 11875
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Yes Mr Noodle! Quotes did the trick, that's awesome!
I'll test with some more files but I think its working OK.

Thanks a lot, so simple.
rpedro
 
Posts: 29
Joined: Wed Jun 27, 2012 6:17 am


Return to Support