read pipe | delimited csv file - Kdb+ / qStudio

Home Forums Kdb+ / qStudio read pipe | delimited csv file

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #175

    Michael
    Guest

    How can I read a pipe delimited file into kdb?

    source.txt:

    name|id|age|height
    P13141|212314|23|167
    R3145|212315|34|190

    #207

    admin
    Keymaster

    For reading a pipe delimited file you can use 0:

    Here I first use read0 to read the file as a list of strings, to demonstrate it’s the same format you gave:

    q)read0 `:source.txt
    "name|id|age|height"
    "P13141|212314|23|167"
    "R3145|212315|34|190"

    On the right hand side of 0: We supply the file handle.
    On the left is a two item list
    “SJII” – denotes the four types for each column – symbol, long, int, int
    enlist “|” – means take the pipe as the delimiter and enlist tells kdb there is a header row
    like so:

    q)("SJII"; enlist "|") 0: `:source.txt
    name id age height
    ------------------------
    P13141 212314 23 167
    R3145 212315 34 190

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.