Hello guys,

I am back with a simple Linux command. This command will let you sum up the numbers line by line on Linux shell. There are two most commonly used and easiest ways to do so.

Create a file named “numbers” containing following random numbers:

3
8
-1
5
0
10
200
151
-20

Sum Numbers using Awk

$ awk 'BEGIN{sum=0}{sum+=$1}END{print sum}' numbers

Sum Numbers using jq

jq is a really superb parser for JSON data. But this handy tool is really a quick option to sum numbers.

$ jq -s 'add' numbers
356

I am keen to hear more handy commands from you all. Keep posting.


Aryan

Hey Friends, Thank you for visiting my blog and spending some time reading it. Myself Aryan who works in computer technologies and keeps on pen down my understanding of various topics. This blog is a write-up of my understanding of various technologies after reading different materials about it. I hope that it helps you in some way.

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *