我有一个文件,其中有n列(不知道提前有多少列).我需要对具有相同column1值的列进行求和并打印它们.除第一列外,所有列均为数字.例如
FILE1.TXT
col1 col2 col3 ... colN
val1 3000 1000 ... 5000
val2 3000 1000 ... 5000
val1 1000 2000 ... 3000
Run Code Online (Sandbox Code Playgroud)
预期产量:
col1 col2 col3 ... colN
val1 4000 3000 ... 8000
val2 3000 1000 ... 5000
Run Code Online (Sandbox Code Playgroud)
我试过了:
awk '{sums[$1] += $2} END { for (i in sums) printf("%s %s\n", i, sums[i])}' file1.txt | sort
Run Code Online (Sandbox Code Playgroud)
这仅打印前两列.我需要添加并打印所有列.
awk ×1