我有一个包含数千行的文件,每行包含一个数字,后跟一行文本。我想将文本相似的行的数字相加。我也希望输出独特的线条。
例如:
25 cup of coffee
75 sign on the dotted
28 take a test
2 take a test
12 cup of coffee
Run Code Online (Sandbox Code Playgroud)
输出将是:
37 cup of coffee
75 sign on the dotted
30 take a test
Run Code Online (Sandbox Code Playgroud)
有什么建议如何在 unix shell 中实现这一点吗?
我查看了Shell 命令对整数求和,每行一个?但这是对文件中所有行的一列数字进行求和,而不仅仅是对相似的文本行进行求和。