UPDATE: added an example to clarify the format of the data.
Considering a CSV with each line formatted like this:
tbl1.col1,tbl1.col2,tbl1.col3,tbl1.col4,tbl1.col5,[tbl2.col1:tbl2.col2]+
where [tbl2.col1:tbl2.col2]+ means that there could be any number of these pairs repeated
ex:
tbl1.col1,tbl1.col2,tbl1.col3,tbl1.col4,tbl1.col5,tbl2.col1:tbl2.col2,tbl2.col1:tbl2.col2,tbl2.col1:tbl2.col2,tbl2.col1:tbl2.col2,tbl2.col1:tbl2.col2,tbl2.col1:tbl2.col2,tbl2.col1:tbl2.col2,tbl2.col1:tbl2.col2
The tables would relate to eachother using the line number as a key which would have to be created in addition to any columns mentioned above.
- Is there a way to use
mysql loadto load the data into
data infile
two separate tables? - If not, what Unix command line tools
would be best suited for this?
no, not directly. load data can only insert into one table or partitioned table.
what you can do is load the data into a staging table, then use
insert intoto select the individual columns into the 2 final tables. you may also needsubstring_indexif you’re using different delimiters for tbl2’s values. the line number is handled by an auto incrementing column in the staging table (the easiest way is to make the auto column last in the staging table definition).the format is not exactly clear, and is best done w/perl/php/python, but if you really want to use shell tools:
this creates table1 and table 2 files with these contents:
and