I have this command that I would like to sum all the numbers from the output.
The command looks like this
$(hadoop fs -ls -R /reports/dt=2018-08-27 | grep _stats.json | awk '{print $NF}' | xargs hadoop fs -cat | jq '.duration')
So it's going to list all the folders in /reports/dt=2018-08-27
and get only _stats.json
and pass that through jq
from hadoop -cat
and get only .duration
from the json. Which in the end I get the result like this.
1211789 1211789 373585 495379 1211789
But I would like the command to sum all those numbers together to become 4504331
You can just use
add
now.Use a
for
loop.Another option (and one that works even if not all your durations are integers) is to make your
jq
code do the work:...properly emits as output:
Replace the
<<<"$sample_data"
with a pipeline on stdin as desired.awk
to the rescue!For clarity and generality, it might be worthwhile defining
sigma(s)
to add a stream of numbers:will do