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í)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. UOS系統(tǒng)怎么滾動(dòng)截圖? UOS滾動(dòng)截圖的使用方法2. Win10服務(wù)項(xiàng)哪些能禁用?3. WinXP沒有網(wǎng)絡(luò)適配器怎么添加?本地連接消失了如何恢復(fù)?4. Debian11中thunar文件管理器在哪? Debian11打開thunar文件管理器的技巧5. 統(tǒng)信uos系統(tǒng)怎么管理打印界面和打印隊(duì)列?6. 如何立即獲取Windows10 21H1更新?獲取Windows10 21H1更新方法分享7. Win10系統(tǒng)麥克風(fēng)沒聲音怎么設(shè)置?8. Win11怎么提高開機(jī)速度?Win11提高開機(jī)速度設(shè)置方法9. Win10系統(tǒng)怎么把字體改成蘋果字體?10. Debian11怎么結(jié)束進(jìn)程? Debian殺死進(jìn)程的技巧

網(wǎng)公網(wǎng)安備