linux - awk create a bulk MySQL insert from csv -
i have huge csv file data, i'm trying generate mysql bulk insert statement.
data presented follows in csv
90927597|1356976813998|1356976814177|1356976817457|17756249959|17756249959|18663111085|17753220005|1090917|1775624995900|a 90927599|1356976813098|1356976814797|1356976823738|12562175250|12562175250|12566502514|12565207040|1890362|1256217525000|a 90927602|1356976813098|1356976814797|1356976823738|12562175250|12562175250|12566502514|12565207040|1890362|1256217525000|a 90927603|1356976813098|1356976814797|1356976823738|12562175250|12562175250|12566502514|12565207040|1890362|1256217525000|a
i'm looking create bulk insert combine every 2 rows single insert statement
mysql statement desired output
insert data (90927597,1356976813998,1356976814177,1356976817457,17756249959,17756249959,18663111085,17753220005,1090917,1775624995900,a,90927599,1356976813098,1356976814797,1356976823738,12562175250,12562175250,12566502514,12565207040,1890362,1256217525000,a); insert data (90927602,1356976813098,1356976814797,1356976823738,12562175250,12562175250,12566502514,12565207040,1890362,1256217525000,a, 90927603,1356976813098,1356976814797,1356976823738,12562175250,12562175250,12566502514,12565207040,1890362,1256217525000,a);
thank you
$ cat tst.awk begin{ fs="|"; ofs="," } { $1 = $1 head = ( (nr%2) == 1 ? tail "insert data (" : "," ) printf "%s%s", head, $0 tail = ");\n" } end { printf "%s", tail } $ awk -f tst.awk file insert data (90927597,1356976813998,1356976814177,1356976817457,17756249959,17756249959,18663111085,17753220005,1090917,1775624995900,a,90927599,1356976813098,1356976814797,1356976823738,12562175250,12562175250,12566502514,12565207040,1890362,1256217525000,a); insert data (90927602,1356976813098,1356976814797,1356976823738,12562175250,12562175250,12566502514,12565207040,1890362,1256217525000,a,90927603,1356976813098,1356976814797,1356976823738,12562175250,12562175250,12566502514,12565207040,1890362,1256217525000,a);
Comments
Post a Comment