i have contents in a file
like
asdfb ... 1
adfsdf ... 2
sdfdf .. 3
I want to write a unix command that should be able to add 1 + 2 + 3 and give the result as 6
From what I am aware grep and awk would be handy, any pointers would help.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I believe the following is what you’re looking for. It will sum up the last field in each record for the data that is read from stdin.
Some things to note:
NFis the number of fields in the current record. By prepending it with a $ we are treating its value as a variable. At least this is how it appears to work anyway 🙂END { }block is only once all records have been processed by the other blocks.