Linux下刪除大資料檔案中部分欄位重複的行

來源:互聯網
上載者:User

最近寫的一個資料擷取程式產生了一個含有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;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.