使用AWK合并基于第一列的唯一行 [英] Using AWK to merge unique rows based on column one
本文介绍了使用AWK合并基于第一列的唯一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写AWK脚本以汇总大文本文件上的数据.结果数据的顺序很重要,因此我不能使用sort.
I am trying to write an AWK script to summarize data on a large text file. The order of the resulting data is important so i can't use sort.
我尝试了FNR == NR的不同变体,但是没有任何运气
I have tried different variations of FNR==NR but haven't had any luck
输入文件
Height 3.5
Weight 12.3
Age 23
:
:
Height 4.5
Weight 15.5
Age 31
:
:
预期产量
Height 3.5 4.5
Weight 12.3 15.5
Age 23 31
推荐答案
使用awk:
awk '{a[$1]=a[$1] FS $2} END{for(i in a) print i a[i]}' file
输出:
Weight 12.3 15.5
Height 3.5 4.5
:
Age 23 31
请参阅: 查看全文