Showing results for 
Search instead for 
Did you mean: 

How to replay csv file one line by one line

New Contributor
Hi, Masters:
  I have some csv files, the format such as:
    timestamp, bid, ask, volumn

  How to replay the data one line by one line into kdb? Or do you have suggestions? Thanks so much!


New Contributor
Depending on the size of your file, you could read it all into memory at once, as a table.

Yes, you're right. I can read the whole csv file into kdb+ without problem.
I just want to replay it line by line based on the recorded timestamp.

Not applicable
Why exactly do you want to replay the .csv file line by line? When you say replay do you mean load into kdb+?

Starting with this table: 
table:([]time:asc 1000000?.z.P;sym:1000000?`abc`def`ghi;price:1000000?100f)
and saving it down: 
`:table.csv 0: csv 0: table
The following options are available to you: 

If you just want to load the csv file into kdb you can do: 

If your .csv file is really big you can use .Q.fs or .Q.fsn 

If you really want to load it line by line, even though I wouldn't recommend this, you can use over and do it this way: 

Let me know if this helps you! 

New Contributor
Alex, thanks!
Yes, the process of your method is working. It can be load into kdb+.

You asked "Why you want to replay the .csv file line by line?". It is because I want to implement a replay service to playback what I had recorded based on the market real tick-by-tick data. Actually, I can load the whole csv file into kdb+, but my purpose is replay the data line-by-line based on the timestamp, such as: 09:00:00, replay line 1; 09:00:01, replay line 2; 09:00:05, replay line 3; and so on. I prefer to have another table to save the streaming data.

New Contributor III
You could either read the csv into memory in one go, or read through it trunk by trunk. (Both of these methods are described in the documentations.)

Once you get the data, may it be all in one go or trunk by trunk, you can replay it whichever way you prefer.

Flying, thanks!
Do you mean the document that Collin mentioned?