Converting QIF Files to CSV


Perl

Image via Wikipedia

I haven't updated Quicken on my Mac since 2006. Yeah, I know, but it does what I want. The program is that my version of Quicken only export QIF format files and Quicken on Windows apparently hasn't supported importing those since 2005 or something.

The problem was that I needed to get some information about my credit card account to my accountant. If you google around, you'll find people who sell programs that convert QIF files to Excel that they want real money for (like $60). Forget that. Especially when I've got Perl at my beck and call.

I found a Perl module called Finance::QIF that seemed to do the trick. There's also a Text::CSV module, as you'd expect. In 10 minutes I had the following little script that did just what I wanted:

#!/usr/bin/perl -w

use Getopt::Std;
use Text::CSV;
use Finance::QIF;

# global options
use vars qw/ %opt /;
my $opt_string = 'h?f:';
getopts( "$opt_string", \\%opt );

my $input_file = "";
if ($opt{'f'} ) {
    $input_file = $opt{'f'} ;
} else {
    die "You must specify an input file with the -f switch.\
";
}
  
my $qif = Finance::QIF->new( file => $input_file, 
\t\t\t     record_separator => "\\r"  );

my $csv = Text::CSV->new(); 
 
print '"Date","Payee","Transaction","Category"', "\
";

while ( my $record = $qif->next ) {
  next unless ($record->{'header'} eq 'Type:CCard' );

  $csv->combine($record->{'date'},
\t\t$record->{'payee'},
\t\t$record->{'transaction'},
\t\t$record->{'category'});
  print $csv->string(), "\
";
}

1;

This is only converting credit card register data because that's all I needed, but it wouldn't be hard to modify it to do something else. If you run this on Windows, you'll likely want the record separator to be "\ " instead of "\\r";

How do people who can't program get by in life? I really don't know what I'd do.