Jump to content
  • 0

awk script


Question

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.

image.png.63088ac28b35f2dd81f810fb5d7d8d6f.png

 

I hope this helps.

Shovon

 

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.

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