Sum of all rows of all columns - Bash

后端 未结 6 415
鱼传尺愫
鱼传尺愫 2021-01-20 02:54

I have a file like this

1 4 7 ...
2 5 8
3 6 9 

And I would like to have as output

6 15 24 ...

That is the

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-20 03:48

    There is a very simple command called numsum to do this:

    numsum -c FileName
    
    -c   ---    Print out the sum of each column.
    

    For example:

    cat FileName
    1 4 7 
    2 5 8
    3 6 9 
    

    Output :

    numsum -c FileName
    6 15 24
    

    Note: If the command is not installed in your system, you can do it with this command:

    apt-get install num-utils
    

提交回复
热议问题