【发布时间】:2019-02-07 19:55:18
【问题描述】:
我有一个包含以下数据的文件:
25 POSIX shell script, ASCII text executable
25 POSIX shell script, ASCII text executable
3 PostScript document text conforming DSC level 3.0, type EPS, Level 2
2 PostScript document text conforming DSC level 3.0, type EPS, Level 2
23 PostScript document text conforming DSC level 3.0, type EPS, Level 2
4 SVG Scalable Vector Graphics image
4 SVG Scalable Vector Graphics image
如果所有其他字段都相同,则希望对第一个字段求和,因此输出应为:
50 POSIX shell script, ASCII text executable
28 PostScript document text conforming DSC level 3.0, type EPS, Level 2
8 SVG Scalable Vector Graphics image
我试过这个 awk 命令:
awk '{ a[$2]+=$1 }END{ for(i in a) print a[i],i }' inputfile
哪个打印:
25 POSIX
28 PostScript
8 SVG
但我找不到打印剩余行的方法
【问题讨论】:
-
数字和第一个字母之间的空格是空白字符还是制表符?
-
那些是空白字符
标签: awk