Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    29

    Question Unanswered: Import data file in "var1=data1 var2=data2" format

    I have a sample file that contains entries like:

    age=24 gender=male height=63 weight=180 eyecolor=blue haircolor=blonde
    age=21 gender=female height=52 weight=140 eyecolor=hazel haircolor=brown
    age=27 gender=female height=48 weight=127 eyecolor=brown haircolor=black

    etc.

    I know how to handle comma or tab delimited data, but I'm not sure what this format is called. I have a table setup with each variable as a column. In some cases, I may have a sample file that only has some of these variables, or maybe more, and may not have them in the same order. So I cannot rely on the position of this data.

    How do I tokenize this, and import it into my table? What is this format called, so I can look up a reference going forward?

  2. #2
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    I don't know if there is an official name, but I would refer to this as "key/value."

  3. #3
    Join Date
    Feb 2004
    Posts
    29
    Quote Originally Posted by dbmab
    I don't know if there is an official name, but I would refer to this as "key/value."
    Thanks. With that tidbit, I'm starting to search for "key/value metadata". My results are a closer match than what I was getting before, but I still haven't gotten an example of how to import this into mysql.

    My instincts tell me I should probably import each line into a temporary array by tokenizing the key/value pairs by the spaces. Then I would parse the array again to be break the entry into a table, using the = as the delimeter. Then a loop would put each value into each column based on the key (if it exists). Seems like an inefficent brute force though...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •