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.
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!
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 ......