SUM UP THE NUMBERS FROM A FILE USING AWK

You have a file with set of numbers and you want to add up all the numbers and print the resultant output. How would you do that?

[root@orcl oracle]# cat numbers
1
2
3
4
5
6

Use the below combination of awk to sum the integers from the file. AWK is very powerful string or number or file manipulation command to print only the specific column of interest from multiple columns

[root@orcl oracle]# awk '{sum+=$1;}END{print sum;}' numbers
21

Leave a Reply