Linux實(shí)現(xiàn)文件內(nèi)容去重及求交并差集
一、數(shù)據(jù)去重
日常工作中,使用Hive或者Impala查詢導(dǎo)出來可能會(huì)存在數(shù)據(jù)重復(fù)的現(xiàn)象,但又不想重新執(zhí)行一遍查詢(查詢時(shí)間稍長(zhǎng),導(dǎo)出文件內(nèi)容多),因此想到了使用Linux命令將文件的內(nèi)容重復(fù)數(shù)據(jù)進(jìn)行去除。
案例如下:
可以看到aaa.txx有3條重復(fù)數(shù)據(jù)
想去掉多余的數(shù)據(jù),只保留一條
sort aaa.txt | uniq > bbb.txt
將aaa.txt文件中重復(fù)數(shù)據(jù)去掉,輸出到bbb.txt
可以看到bbb.txt文件中只保留了一條數(shù)據(jù)
二、數(shù)據(jù)交、并、差
1)、交集(相當(dāng)于user_2019 inner join user_2020 on user_2019.user_no=user_2020.user_no)
sort user_2019.txt user_2020.txt | uniq -d
2)、并集(相當(dāng)于 user_2019.user_no union user_2020.user_no)
sort user_2019.txt user_2020.txt | uniq
3)、差集
user_2019.txt-user_2020.txt
sort user_2019.txt user_2020.txt user_2020.txt | uniq -u
user_2020.txt - user_2019.txt:
sort user_2020.txt user_2019.txt user_2019.txt | uniq -u
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。