LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2022, 04:32 AM   #1
vanKey
LQ Newbie
 
Registered: Jun 2022
Posts: 17

Rep: Reputation: 0
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
 
Old 06-17-2022, 04:46 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,976

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
is there any question here? Do you need any help? Is it a duplicate again?
 
Old 06-17-2022, 11:03 AM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
@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!
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Calculate time with awk with an exception for the last line jostber Programming 9 04-17-2013 08:17 AM
grab the line below a blank line and the line above the next blank line awk or perl? Pantomime Linux - General 7 06-26-2008 08:13 AM
how to sort output at latest entries without disturbing the previous entries record nabmufti Programming 4 02-11-2008 11:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration