linux - transform csv file to mysql insert statement -
i'm trying generate mysql file csv data
90927744|1356976814398|0|1356976815339|18563182571|18563182571|18568753009|18563574221
is there way use awk or sed generate mysql insert statement follows
insert table (id,value,status,starttime,endtime,number,phone,number) values (90927744,1356976814398,0,1356976815339,18563182571,18563182571,18568753009,18563574221);
thank you
to extract particular field input....
$echo "90927744|1356976814398|0|1356976815339|18563182571|18563182571|18568753009|18563574221" | awk -f "|" '{print $4}' 1356976815339
if have 1 line in a.txt
(see script below multiple lines in input file)
$cat a.txt | awk -f "|" '{print $4}'
so output query want--
$cat a.txt | awk -f "|" '{printf("insert table (id,value,status,starttime,endtime,number,phone,number) values (%d, %d, %d, %d, %d, %d, %d, %d) \n", $1, $2, $3, $4, $5, $6, $7, $8)}'
if file has multiple lines, use following script (or adapt needs)
while read line echo "$line" | awk -f "|" ........ done < a.txt
Comments
Post a Comment