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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s