Linux下刪除大數(shù)據(jù)文件中部分字段重復行的方法
發(fā)布日期:2022-03-14 13:36 | 文章來源:CSDN
最近寫的一個數(shù)據(jù)采集程序生成了一個含有1千多萬行數(shù)據(jù)的文件,數(shù)據(jù)由4個字段組成,按照要求需要刪除第二個字段重復的行,找來找去linux下也沒找到合適的工具,sed/gawk等流處理工具只能針對一行一行處理,并無法找到字段重復的行??磥碇缓米约簆ython一個程序了,突然想起來利用mysql,于是進行乾坤大挪移:
1. 利用mysqlimport --local dbname data.txt導入數(shù)據(jù)到表中,表名要與文件名一致
2. 執(zhí)行下列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;
1. 利用mysqlimport --local dbname data.txt導入數(shù)據(jù)到表中,表名要與文件名一致
2. 執(zhí)行下列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;
版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
相關(guān)文章