Jump to content
  • 0

awk script


1 answer to this question

Recommended Posts

  • 0
On 12/15/2020 at 8:45 PM, Himanshu Gupta said:

How to write an awk script to print sum of fields in every line of the data given


Hi Himanshu,

You can use the following awk command to print the sum of all the columns of each line of the numbers.txt file:

$ awk '{for(i=1; i<=NF; i++) sum+=$i; print sum}' numbers.txt


An example is given in the screenshot below.



I hope this helps.



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...