一、數(shù)據(jù)去重
日常工作中,使用Hive或者Impala查詢(xún)導(dǎo)出來(lái)可能會(huì)存在數(shù)據(jù)重復(fù)的現(xiàn)象,但又不想重新執(zhí)行一遍查詢(xún)(查詢(xún)時(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í)有所幫助,也希望大家多多支持腳本之家。