creating QIF file under Dos using AWK

AC gnucash at acarver.net
Sun Mar 8 19:02:34 EDT 2015


FS needs to be used in a BEGIN block or from the command line.  Also, to
skip the first two lines don't use NR, instead make your own counter,
count off the first two lines and toss them away then begin parsing the
data.

(Note the following should be in its own file and then executed using
the -f option of awk,  you are also missing the type field, and the
order of the fields should be Type, then D, then T, then P and then the
caret).

If you write your script into a script file that is read into awk using
the -f command, you do not need to escape characters except for control
characters (newline, carriage return, etc.)  So the caret/circumflex
would be a simple string as below

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 "^"
	}
}

For the following five lines in a sample import file called test.qif
(note that the description is prefixed A, B, C, D and E to distinguish
the lines):

$ cat test.qif
2006-09-27,AONLINE BILL PAYMENT: Bank of Example 123938568,250.00
2006-09-27,BONLINE BILL PAYMENT: Bank of Example 123938568,250.00
2006-09-27,CONLINE BILL PAYMENT: Bank of Example 123938568,250.00
2006-09-27,DONLINE BILL PAYMENT: Bank of Example 123938568,250.00
2006-09-27,EONLINE BILL PAYMENT: Bank of Example 123938568,250.00

I wrote the above script into a file called qifconvert.awk and ran the
script.  The result is below (note I'm using a script file to avoid
having to write shell escape sequences, do this instead of trying to
write your script on the command line):

$ awk -f qifconvert.awk < test.qif
!Type:Bank
D2006-09-27
T250.00
PCONLINE BILL PAYMENT: Bank of Example 123938568
^
!Type:Bank
D2006-09-27
T250.00
PDONLINE BILL PAYMENT: Bank of Example 123938568
^
!Type:Bank
D2006-09-27
T250.00
PEONLINE BILL PAYMENT: Bank of Example 123938568
^


On 2015-03-08 04:46, piggyb wrote:
> Thank for letting me know how to use a external script 
> Because I am using a comma separated file, I tried these scripts
> 
> /NR <2 {FS =";"}{ print "D" $1; print "P" $2; print "T" $3; print "^"; }
> NR <2 {FS ="\"*;\"*"}{ print "D" $1; print "P" $2; print "T" $3; print "^";
> }/
> 
> But now the script reads form the first line and displays a comma in front
> of the bank-number 
> 
> 
> KNAB EXPORT													
> BankAcount	Transactiondate	Valutacode	CreditDebet	Amount	Banknr	bankaccount
> date	 Method 	Discription	Type	Machtigingsnummer	authorization Number 	Adres
> 123456	31-12-2014	EUR	C	50	987569	gnucash	01-01-2015	iDEAL	Contract 154543				
> 123457	31-12-2014	EUR	D	60	987570	gnucash	31-12-2014	iDEAL	Contract 154544	
> HKU0000324354537934	KSADASD35342434235	Hippo Land
> 123458	31-12-2014	EUR	D	70	987571	gnucash	31-12-2014	iDEAL	Contract 154545	
> HKU0000000000000001	KSADASD1	Hippo Land
> 123459	31-12-2014	EUR	D	71	987572	gnucash	31-12-2014	iDEAL	Contract 154546	
> HKU0000000000000002	KSADASD2	Hippo Land
> 123460	30-12-2014	EUR	C	72	987573	gnucash	30-12-2014	iDEAL	Contract 154547	
> HKU0000000000000003	KSADASD3	Hippo Land
> 123461	30-12-2014	EUR	C	73	987574	gnucash	30-12-2014	iDEAL	Contract 154548	
> HKU0000000000000004	KSADASD4	Hippo Land
> 123462	30-12-2014	EUR	C	74	987575	gnucash	30-12-2014	iDEAL	Contract 154549	
> HKU0000000000000005	KSADASD5	Hippo Land
> 123463	30-12-2014	EUR	D	75	987576	gnucash	30-12-2014	iDEAL	Contract 154550	
> HKU0000000000000006	KSADASD6	Hippo Land
> 123464	29-12-2014	EUR	D	76	987577	gnucash	29-12-2014	iDEAL	Contract 154551	
> HKU0000000000000007	KSADASD7	Hippo Land
> 
> 
> 
> 
> 
> 
> --
> View this message in context: http://gnucash.1415818.n4.nabble.com/creating-QIF-file-under-Dos-using-AWK-tp4676673p4676720.html
> Sent from the GnuCash - User mailing list archive at Nabble.com.
> _______________________________________________
> 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.
> 
> 



More information about the gnucash-user mailing list