我想从这个链接计算所有.mobi文件的总大小 (顺便说一句,这是一个很好的链接).
在我尝试将此作为我的学习经验时,我制作了一个"管道"(让我们称之为a),从该页面输出所有大小,如下所示:
189K
20M
549K
2.2M
1.9M
3.1M
2.5M
513K
260K
1.1M
2.8M
5.1M
3.7M
1.5M
5.6M
1.0M
5.6M
1.5M
4.9M
3.4M
810K
Run Code Online (Sandbox Code Playgroud)
我的目标是获得总大小(例如:50.50M,或50000K) - 所有这些数字的总和.我的问题是,如何使用pipeling(a | some_other_commands)计算该目标.欢迎使用python或任何其他语言(最好是一个内容)的答案.非常感谢.
为了有趣的shell解决方案:
a | sed -e 's/M$/ 1024 * +/' -e 's/K$/ +/' | dc -e '0' -f - -e 'p'
Run Code Online (Sandbox Code Playgroud)