2020年5月20日 星期三

[linux] How to merge two files based on the same columns awk 使用 awk 根據某欄位 merge join 檔案

How to merge two files based on the same columns awk 使用 awk 根據某欄位 merge join 檔案

group_score.csv

寶兒樂,,,,,20.950745,16.072779,1,1
盛香珍瓜子,,,,,27.969128,24.331234,1,1
小型吸塵器,15.214106,15.214106,90,90,15.214106,12.962197,90,1
日本ariel洗衣精,,,,,33.072052,24.553936,1,1

querylog
寶兒樂
小型吸塵器
日本ariel洗衣精
盛香珍瓜子



awk -F',' 'NR==FNR{a[$1]=$0;next}{print a[$1]}' group_score.csv querylog


Ref
NR==FNR
text processing - How to merge two files based on the matching of two columns? - Unix & Linux Stack Exchange https://unix.stackexchange.com/questions/113898/how-to-merge-two-files-based-on-the-matching-of-two-columns
awk之NR==FNR问题 - 陈浩然201 - 博客园 https://www.cnblogs.com/irockcode/p/7044722.html
awk - What are NR and FNR and what does "NR==FNR" imply? - Stack Overflow https://stackoverflow.com/questions/32481877/what-are-nr-and-fnr-and-what-does-nr-fnr-imply
AWK tutorial: awk merge files base on the keyword - LinuxCommands.site https://www.linuxcommands.site/linux-text-processing-commands/linux-awk-command/awk-merge-files/

沒有留言:

張貼留言