gpt4 book ai didi

linux - 如何比较unix中不同列的文件?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:22:45 25 4
gpt4 key购买 nike

我想比较 Today.txt 和 Main.txt 的文件名。如果匹配,则打印 Main.txt 匹配文件的所有 6 列,并使用新文件 matched.txt。

以及与Main.txt不匹配的文件,然后在新文件say unmatched.txt中列出TODAY.txt的文件名和时间

主.txt

 date      filename          timestamp space  count   status
Nov 4 +CHCK01_20161104.txt 06:39 2.15M 17153 on_time
Nov 4 TRIPS11_20161104.txt 09:03 0.00M 24 On_Time
Nov 4 AR02_20161104.txt 09:31 0.00M 7 On_Time
Nov 4 AR01_20161104.txt 09:31 0.04M 433 On_Time

今天.txt

 filename       time
CHCK01_20161104.txt 06:03
CHCK05_20161104.txt 11:10
CHCK09_20161104.txt 21:46
AR01_20161104.txt 09:36
AR02_20161104.txt 09:36
ifs01_20161104.txt 21:16
TRIPS11_20161104.txt 09:16

要求的输出:匹配.txt

Nov 4    +CHCK01_20161104.txt  06:39   2.15M  17153    on_time
Nov 4 TRIPS11_20161104.txt 09:03 0.00M 24 On_Time
Nov 4 AR02_20161104.txt 09:31 0.00M 7 On_Time
Nov 4 AR01_20161104.txt 09:31 0.04M 433 On_Time

不匹配.txt

CHCK05_20161104.txt 11:10
CHCK09_20161104.txt 21:46
ifs01_20161104.txt 21:16

你能帮我解决这个问题吗?

提前致谢!

最佳答案

awk 助您一臂之力!

$ awk 'FNR==1{next} 
NR==FNR{a[$1]=$2; next}
$3 in a{print; delete a[$3]}
END{for(k in a) print k,a[k] > "unmatched"}' today main > matched

$ head *matched

==> matched <==
Nov 4 CHCK01_20161104.txt 06:39 2.15M 17153 on_time
Nov 4 TRIPS11_20161104.txt 09:03 0.00M 24 On_Time
Nov 4 AR02_20161104.txt 09:31 0.00M 7 On_Time
Nov 4 AR01_20161104.txt 09:31 0.04M 433 On_Time

==> unmatched <==
ifs01_20161104.txt 21:16
CHCK09_20161104.txt 21:46
CHCK05_20161104.txt 11:10

关于linux - 如何比较unix中不同列的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40439489/

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