bash命令总结一列数 [英] Bash command to sum a column of numbers

查看:116
本文介绍了bash命令总结一列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想bash命令,我可以管成将总结一列数。我只是想要一个快速班轮会做一些本质上是这样的:

 猫FileWithColumnOfNumbers.txt |和


解决方案

使用现有的文件:

 粘贴-sd + INFILE |公元前

使用标准输入:

 <&CMD GT; |粘贴-sd + |公元前

编辑:
对于某些粘贴的需要实现从阅读时要更加明确的标准输入的:

<&CMD GT; |粘贴-sd + - | BC

I want a bash command that I can pipe into that will sum a column of numbers. I just want a quick one liner that will do something essentially like this:

cat FileWithColumnOfNumbers.txt | sum

解决方案

Using existing file:

paste -sd+ infile | bc

Using stdin:

<cmd> | paste -sd+ | bc

Edit: With some paste implementations you need to be more explicit when reading from stdin:

<cmd> | paste -sd+ - | bc

这篇关于bash命令总结一列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆