gpt4 book ai didi

Unix:使用第二列合并2个文件

转载 作者:行者123 更新时间:2023-12-04 18:36:22 25 4
gpt4 key购买 nike

我想根据第二列的内容合并两个文件。

文件1:

"4742"  "209220_at"     2.60700394801826
"104" "209396_s_at" 2.60651442103297
"749" "202409_at" 2.59424724783704
"4168" "209875_s_at" 2.58773204877464
"3973" "1431_at" 2.52832098784342
"1826" "207201_s_at" 2.41685345240968

文件2:
"653"   "1431_at"       2.14595534191867
"1109" "207201_s_at" 2.13777517447307
"353" "212531_at" 2.12706340284672
"381" "206535_at" 2.11456707231618
"1846" "204534_at" 2.10919474441178

最终拥有:
"3973"  "1431_at"       2.52832098784342 "653"   "1431_at"       2.14595534191867
"1826" "207201_s_at" 2.41685345240968 "1109" "207201_s_at" 2.13777517447307

我已经尝试过 commdiff,一些晦涩的 awk一线但没有成功。
任何帮助,不胜感激。

最佳答案

awk '
# store the first file, indexed by col2
NR==FNR {f1[$2] = $0; next}
# output only if file1 contains file2's col2
($2 in f1) {print f1[$2], $0}
' file1 file2

关于Unix:使用第二列合并2个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4971756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com