0

In shell script a command output gives integer number like :

xxx$> xxxx
10
20
30

I want to add those integer values and get sum value. What is the simplest way to do..?

0

1 Answer 1

4

Supposing your script is named xxxx, you could do :

xxxx | awk '{sum+=$1} END {print sum}'

Which would print the sum of the integers printed by xxxx :

~$ xxxx
10
20
30
~$ xxxx | awk '{s+=$1} END {print s}'
60
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.