第一档的内容:
$cat File1
KEY1,4999
KEY2,3999
KEY3,5999
KEY4,10999
第二档的内容:
$cat File2
KEY1,11905
KEY2,6872
KEY3,2393
KEY4,296360
预期的输出文件:
KEY1,4999
KEY2,3999
KEY3,2393
KEY4,10999
搜索单线程命令以获得预期输出。这里的要求是通过比较两个文件为每个键打印较少的数字。
答案 0 :(得分:3)
(click)="sayHello(); $event.stopPropagation()"
是"您的朋友"在这种情况下:
Awk
输出:
awk 'BEGIN{ FS=OFS="," }
NR==FNR{ a[$1]=$2; next }
$1 in a{
print $1, ($2 < a[$1]? $2 : a[$1])
}' file1 file2
答案 1 :(得分:2)
awk
可以是你的朋友
$ cat f1
KEY1,4999
KEY2,3999
KEY3,5999
KEY4,10999
$ cat f2
KEY1,11905
KEY2,6872
KEY3,2393
KEY4,296360
$ awk -v FS="," '{$0=($2<$4)?$1 "," $2:$3 "," $4}1' <(paste -d',' f1 f2)
KEY1,4999
KEY2,3999
KEY3,2393
KEY4,10999