小编Ton*_*ony的帖子

Shell 命令对文件中相似文本行的数字进行求和

我有一个包含数千行的文件,每行包含一个数字,后跟一行文本。我想将文本相似的行的数字相加。我也希望输出独特的线条。

例如:

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 命令对整数求和,每行一个?但这是对文件中所有行的一列数字进行求和,而不仅仅是对相似的文本行进行求和。

bash shell scripting

3
推荐指数
1
解决办法
1451
查看次数

标签 统计

bash ×1

scripting ×1

shell ×1