简体   繁体   English

比较两个具有不同列的文件

[英]comparing two files with different columns

i have the two files(count.txt, count1.txt). 我有两个文件(count.txt,count1.txt)。 i need to do the following 我需要执行以下操作
1. get the values from count.txt and count1.txt where 1st column is equal. 1.从count.txt和count1.txt中获取值,其中第一列相等。
2. if its equal need to compare the 2nd column like ((1st column value + 5) >= 2 column value) 2.如果相等,则需要比较第二列(((第一列值+ 5)> = 2列值)

count.txt count.txt

order1,150
order2,165
order3,125

count1.txt count1.txt

order1,155
order2,170
order3,125
order4,123

and i want the output like below, 我想要下面的输出,

Output.txt Output.txt

order1,155
order2,170

i have used below nawk command for the 1st point, but not able to complete the 2nd point. 我已经在nawk命令下面使用了第一点,但是无法完成第二点。 Please suggest to achieve the same. 请提出同样的建议。
nawk -F"," 'NR==FNR {a[$1];next} ($1 in a)' count.txt count1.txt

nawk -F"," 'NR==FNR {a[$1]=$2;next} ($1 in a) && (a[$1]+5)<=$2' count.txt count1.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM