Search code examples
kdb

Importing text data with variable size separators in kdb


I want to import a text file where the columns are separated by a variable number of spaces:

A    123
B 222
C  211

Running this won't work well:

f: ("CI"; " ") 0: `$(":myfile")

Solution

  • You can strip the excess spaces as you import it:

    ("CI";" ")0:(ssr[;"  ";" "]/) each read0`:myfile
    
    A   B   C
    123 222 211
    

    This will likely dramatically slow things down though.

    Can you fix the data at the source? Why is there variable numbers of spaces?