search

Loading

Friday, May 31, 2013

Print sum of all numbers in a file in linux using awk

This is to print the sum of all numbers in a file using awk.

If the file which we want to process is sum.txt, and it's content is :

cat sum.txt
1
3
2
4
5


 To find the sum of all these numbers we can use below command:

How to join all lines in a file using comma as delimiter?

Sometimes we want to combine the lines in a file as single line. How to achieve this in linux using command line?

We can use the command 'paste' for this purpose.

From its man page,

paste - merge lines of files