Home > Database > Mysql Tutorial > body text

Linux下删除大数据文件中部分字段重复的行

WBOY
Release: 2016-06-07 17:08:06
Original
914 people have browsed it

最近写的一个数据采集程序生成了一个含有1千多万行数据的文件,数据由4个字段组成,按照要求需要删除第二个字段重复的行,找来找

最近写的一个数据采集程序生成了一个含有1千多万行数据的文件,,数据由4个字段组成,按照要求需要删除第二个字段重复的行,找来找去linux下也没找到合适的工具,sed/gawk等流处理工具只能针对一行一行处理,并无法找到字段重复的行。看来只好自己python一个程序了,突然想起来利用mysql,于是进行乾坤大挪移:

1. 利用mysqlimport --local dbname data.txt导入数据到表中,表名要与文件名一致
2. 执行下列sql语句(要求唯一的字段为uniqfield)

use dbname;

alter table tablename add rowid int auto_increment not null;

create table t select min(rowid) as rowid from tablename group by uniqfield;

create table t2 select tablename .* from tablename,t where tablename.rowid= t.rowid;

drop table tablename;

rename table t2 to tablename;

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!