WebHosting

Tuesday, January 8, 2013

Linux: Add numbers in a column in a file

In windows we use Excel to add all the numbers in a column. But how about Unix/Linux?
We encountered such an requirement and we got the answer too.
Actually solution in much more simpler than the problem..!

Mission accomplished by 'awk' command. Its merely a very powerful and useful command.
Here is an example for it:


I've a file num.test with below values in it. 


# cat num.test

1
2
3
4
5

Now that I want to add all these values in a single command. Here's the answer:

#awk '{s+=$1} END {print s}' num.test

15

Just simple as that!

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

How to Enable and Configure Remote Desktop (RDP) on Ubuntu 24.04.4 LTS

Remote Desktop Protocol (RDP) support in Ubuntu has become considerably easier with the GNOME Remote Desktop stack included in modern Ubuntu...