简体   繁体   English

将.csv导入MySQL时如何跳过中间行

[英]How to skip intermediate rows when importing .csv to MySQL

I need to import standardized .csv files into a MySQL database, but the files need to be cleaned up before they're turned into tables (remove repeating headers, dates, etc.). 我需要将标准化的.csv文件导入到MySQL数据库中,但是在将文件转换为表格之前,必须先对其进行清理(删除重复的标头,日期等)。 Each .csv file is exactly 111 lines and has the same spacing and formatting, so I'd like to build a SQL command that skips the appropriate rows in each file and imports the rest into a table. 每个.csv文件正好是111行,并且具有相同的间距和格式,因此我想构建一个SQL命令,该命令将跳过每个文件中的适当行,并将其余的行导入表中。

Is it possible to do this? 是否有可能做到这一点? I know I can 'IGNORE 1 ROWS' to get past the first row(s), but what about rows further down? 我知道我可以“ IGNORE 1 ROWS”跳过第一行,但是接下来的行又如何呢?

Sorry, in the comment you cant see the ticks 抱歉,在评论中您看不到刻度线

You can do it with 1 line of shell script: 您可以使用1行shell脚本来做到这一点:

line=`head -n 1 standardized.csv`; grep -v "$line"  standardized.csv > new_standardized.csv 

and then import the new_standardized,csv 然后导入new_standardized,csv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM