I have four csv files, and I want to update a set of three, based on the values in the fourth file.
- file_1 contains names.
- file_2 their numerical ids.
- file_3 contains ids from file_1 and file_2, and values corresponding to each pair of id combinations.
- file_4 contains values from some new name combinations.
What I need to do is append file_4's new names to file_1 and file_2, and auto-incrementally create ids for them. Then insert the values in file_3 according to the new id combinations. The problem is quite simple as explained by the example below, what complicates it a little bit is the presence of comma delimited sub-fields like "1,2,3" in some of the csvs.
I need to use a script to achieve this, though I realize it may be easier to use sql.
nid,vname 1,name1 2,name2 3,name3
did,dname 1,"s1,s2,s3" 2,s4 3,"s5,s6"
nid,did,value 1,1,aa 1,2,gg 1,3,tt 2,1,aa 2,2,ag 2,3,at 3,1,aa 3,2,tt
new_name,new_dataset,value name1,"s7,s8",aa name2,"s9,s10",gg name8,"s1,s2,s3",aa
So the three updated files should look like:
nid,vname 1,name1 2,name2 3,name3 4,name8
did,dname 1,"s1,s2,s3" 2,s4 3,"s5,s6" 4,"s7,s8" 5,"s9,s10"
nid,did,value 1,1,aa 1,2,gg 1,3,tt 1,4,aa 2,1,aa 2,2,ag 2,3,at 2,5,gg 3,1,aa 3,2,tt 4,1,aa