Add to CSV file

213 views
Skip to first unread message

Drew

unread,
May 28, 2013, 6:29:08 AM5/28/13
to personal...@googlegroups.com
Is there anyway to directly insert rows into existing csv file - possibly similar to inserting into flat file?

Ryan Hamilton

unread,
May 28, 2013, 6:42:10 AM5/28/13
to personal...@googlegroups.com
Hi Drew,

Appending using a file handle works, I advise testing memory usage and
running on larger files.

// Write to file for first time
q)t:([] a:1 2 3; b:`pp`oo`ii)
q)save `t.csv
`:t.csv

// check contents
q)("**";",")0:`t.csv
,"a" ,"1" ,"2" ,"3"
,"b" "pp" "oo" "ii"

// append using file handle
q)h:hopen `:t.csv
q)neg[h] each ","0:value flip t
-164 -164 -164i

// check contents
q)("**";",")0:`t.csv
,"a" ,"1" ,"2" ,"3" ,"1" ,"2" ,"3"
,"b" "pp" "oo" "ii" "pp" "oo" "ii"

Regards,
Ryan Hamilton


--
TimeStored.com - KDB+ Training, Consulting, Software



On 5/28/2013 11:29 AM, Drew wrote:
> Is there anyway to directly insert rows into existing csv file -
> possibly similar to inserting into flat file? --
> You received this message because you are subscribed to the Google
> Groups "Kdb+ Personal Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to personal-kdbpl...@googlegroups.com.
> To post to this group, send email to personal...@googlegroups.com.
> Visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>

Drew

unread,
May 28, 2013, 8:14:12 AM5/28/13
to personal...@googlegroups.com
Ah excellent, cheers Ryan!

Attila Vrabecz

unread,
May 29, 2013, 4:19:02 AM5/29/13
to [kdb+] [kdb+]

line-by-line is slow, do whole blocks instead
q)neg[h]","0:value flip t

Cheers,
   Attila

--
Reply all
Reply to author
Forward
0 new messages