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

Warp AI Terminal 🔥 | The Future of Coding? Agentic Dev Environment Explained!

  Warp AI Terminal 🔥 | The Future of Coding? Agentic Dev Environment Explained! What if your terminal could think, assist, and even act li...