LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Calculate with line entries (https://www.linuxquestions.org/questions/programming-9/calculate-with-line-entries-4175713534/)

vanKey 06-17-2022 04:32 AM

Calculate with line entries
 
Hello all,

for the following file test.dat, I'm trying to do a simple calculation with the single line entries for every row.

content of test.dat:
Code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15


The task is to calculate the line entries like that:
Code:

(7+10+13)/3 --> write result to row 16
(8+11+14)/3 --> write result to row 17
(9+12+15)/3 --> write result to row 18

Is there an easy way to do this with awk?
I tried
Code:

awk '{print ($7+$10+$13)/3}' test.dat >> check.dat
and it works.

Kind regards

pan64 06-17-2022 04:46 AM

is there any question here? Do you need any help? Is it a duplicate again?

astrogeek 06-17-2022 11:03 AM

@vanKey: Please review the Site FAQ for guidance in asking well formed questions. Especially visit the link from that page, How to Ask Questions the Smart Way for discussion of things to consider when asking others for help.

Everyone here is happy to help you learn, but please make effort to formulate your questions more completely with the necessary context and applicable example data, and add questions which are just variations on each theme to the original threads. Doing so helps others to follow the longer discussion and makes the whole context clear to future visitors.

From the above linked page:

Quote:

If you are unwilling or unable to ask questions in a manner that allows us to help you, it's unlikely our community will be able to provide you a solution. Unfortunately, serial offenders who show wanton disregard for this request after multiple pointers may be asked to seek help elsewhere.
Thanks!


All times are GMT -5. The time now is 02:37 PM.