Shell script not working -> change contents of OFX file

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:
Option 2:
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:
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>