我正在使用下面的查詢插入數據從csv到shell腳本中的MySQL。我需要刪除第一行,即插入時的標題名稱沒有提及他們的名字如何刪除第一行,而使用shell腳本插入csv到mysql
for _csv_file in ${_csv_files[@]}
do
export IFS=","
cat $_csv_file | while read a b c d e f g h i j k l m n o p q r s t u v; do mysql -u $_db_user -p$_db_password $_db << eof
INSERT INTO \`csv_temp_table\`
(\`ProductType\`,\`ProductTypea\`,\`ProductTypeb\`,
\`ProductTypec\`,\`ProductTyped\`,\`ProductTypee\`,
\`ProductTypef\`,\`ProductTypge\`,\`ProductTypeh\`,
\`ProductTypeh\`,\`ProductTypej\`,\`ProductTypke\`,
\`ProductTypel\`,\`ProductTypem\`,\`ProductTypen\`,
\`ProductTypeo\`,\`ProductTyppe\`,\`ProductTypeq\`,
\`ProductTyper\`,\`ProductTypes\`,\`ProductTypet\`,
\`ProductTypeu\`) VALUES ('$a','$b','$c','$d','$e','$f','$g','$h','$i',
'$j','$k','$l','$m','$n','$o','$p','$q','$r','$s','$t','$u','$v',);
eof
done
done
exit;
請幫我完成那個,謝謝。
用'tail -n +2 $ _csv_file'替換'cat $ _csv_file'? – anishsane
@anishsane非常感謝你! –
請注意,引用您的變量:'$ _csv_file' - >'「$ _csv_file」','$ {_ csv_files [@]}' - >'「$ {_ csv_files [@]}」等 – anishsane