Using AWK to merge unique rows based on column one
问题 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. I have tried different variations of FNR==NR but haven't had any luck Input file Height 3.5 Weight 12.3 Age 23 : : Height 4.5 Weight 15.5 Age 31 : : Expected Output Height 3.5 4.5 Weight 12.3 15.5 Age 23 31 回答1: With awk: awk '{a[$1]=a[$1] FS $2} END{for(i in a) print i a[i]}' file Output: Weight 12.3 15.5 Height 3.5 4.5 : Age 23 31 Derived from: how to