creating QIF file under Dos using AWK

Edward Doolittle edward.doolittle at gmail.com
Sun Mar 8 23:28:33 EDT 2015


Perhaps it would be a good idea to transition from awk to Perl in the
documentation, because Perl is installed alongside GnuCash (for
Finance::Quote).

Here's a 30-second Perl hack to accomplish roughly the same thing as the
awk script:

#!/usr/bin/perl
# usage: csvtoqif.pl < infile.csv > outfile.qif
use strict;
use warnings;

# skip first two input lines
<>;
<>;

print "!Type Bank\n";
while (<>) {
  chomp;
  if (/([^,]*),([^,]*),([^,]*)/) {
    print "D", $1, "\n";
    print "T", $3, "\n";
    print "P", $2, "\n";
    print "^\n";
  }
}

Admittedly it looks like gibberish in parts, and there is room for
improvement (e.g., better CSV processing, correct newline character(s) for
various operating systems). But Perl also has the advantage of a huge
library available for robust CSV processing and correct newline characters
and on and on.


On 8 March 2015 at 17:23, AC <gnucash at acarver.net> wrote:

> On 2015-03-08 16:19, Michael DeBusk wrote:
> > On Sun, Mar 8, 2015 at 7:02 PM, AC <gnucash at acarver.net> wrote:
> >
> >> BEGIN {FS=","; line=0}
> >> #you said your entries are comma delimited so you should be using
> >> #a comma not a semicolon as the field separator
> >> {
> >>         line++
> >>         if ( line < 3 ) { next }
> >>         else
> >>         {
> >>                 print "!Type:Bank"
> >>                 print "D" $1
> >>                 print "T" $3
> >>                 print "P" $2
> >>                 print "^"
> >>         }
> >> }
> >
> > Is it desirable to have "!Type:Bank" in each entry? AFAIK, it belongs
> > only at the top of the file.
> >
>
> According to the QIF file format information link that is provided in
> the Gnucash wiki (the link goes to Wikipedia:
> http://en.wikipedia.org/wiki/QIF) it is required on each transaction.
> If not then that isn't clear from the samples.
> _______________________________________________
> gnucash-user mailing list
> gnucash-user at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-user
> -----
> Please remember to CC this list on all your replies.
> You can do this by using Reply-To-List or Reply-All.
>



-- 
Edward Doolittle
Associate Professor of Mathematics
First Nations University of Canada
1 First Nations Way, Regina SK S4S 7K2

« Toutes les fois que je donne une place vacante, je fais cent mécontents
et un ingrat. »
-- Louis XIV, dans Voltaire, Le Siècle de Louis XIV, Chap. XXVI


More information about the gnucash-user mailing list