Sponsored Content
Top Forums Shell Programming and Scripting awk to find the avg of every 3 rows but only show last result? Post 302907019 by JohnnyEnglish on Wednesday 25th of June 2014 11:36:20 AM
Old 06-25-2014
awk to find the avg of every 3 rows but only show last result?

Hi,

I've got as far as this:
Code:
awk '{sum+=$1}(NR%3==1){avg=sum/3; print avg}' input.txt

Input it:
Code:
0.1
txt
txt
0.2
txt
txt
0.3
txt
txt

So, the I get the results:

Code:
0.0333333
0.133333
0.2

It's the last line (0.2) I'm interested in, basically it's the timings from cUrl I'm trying to average. Ideally I'd want to have to awk keep running for n amount of lines, if I need to up the re-running of the check.

How can I get it just to print the last result, or to pull the last result as a variable into my next if this do that nugget?

Thanks in advance, I think I broke google looking for the answer, sorry if I've slowed down your searches today (and yesterday).
Moderator's Comments:
Mod Comment Please use CODE tag for sample input and output as well as for sample code.

Last edited by Don Cragun; 06-26-2014 at 02:13 PM.. Reason: Add CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Show result only if number is greater then

Hello all Im trying to write one liner that will show me results only if the result of the expression is greater then 0 For example: I do : find . -name "*.dsp" | xargs grep -c SecurityHandler the result are : ./foo/blah/a.dsp:0 ./foo/blah1/b.dsp:1 ./foo/blah2/c.dsp:2... (1 Reply)
Discussion started by: umen
1 Replies

2. UNIX for Dummies Questions & Answers

how to use find commnad to show only path of the result

Hello all say i like to find files i do : find . -name "*.txt" but if i like to find ( and print out ) only the path's where the files are ( the *.txt files ) what can i add to the find command ? (1 Reply)
Discussion started by: umen
1 Replies

3. Shell Programming and Scripting

Find avg using awk

Hi, i need some help plz... The file data.txt contains: code of student,surname and name,code of lesson,grade of lesson.The number of lessons of each student is not the same. 25,Jackson Steve,12,4,34,2,65,2 29,Jordan Mary,13,6,23,8,56,4,34,2 04,Leven Kate,14,6,15,6,26,4 34,Owen... (10 Replies)
Discussion started by: Steve_09
10 Replies

4. Shell Programming and Scripting

Comparing rows in same file and writing the result in new file

Help needed... Can you tell me how to compare the last two couple entries in a file and print their result in new file..:confused: I have one file Check1.txt \abc1 12345 \abc2 12327 \abc1 12345 \abc2 12330 I want to compare the entries in Check1 and write to... (1 Reply)
Discussion started by: kichu
1 Replies

5. UNIX for Dummies Questions & Answers

[diff] hide missing rows, show similar

Hi all! Having the following two csv files: file1 AAA;0000;RED CCC;9900;GREEN file2 AAA;0000;BLACK BBB;0099;BLU What's the correct syntax to hide only the missing rows (BBB,CCC) and show the rows that differ only with last field? I expect something like this: diff <options> file1... (2 Replies)
Discussion started by: Evan
2 Replies

6. Shell Programming and Scripting

Avg using awk

Coins: gold 1 1986 USA American Eagle gold 1 1908 Austria-Hungary Franz Josef 100 Korona silver 10 1981 USA ingot gold 1 1984 Switzerland ingot gold 1 1979 RSA Krugerrand gold 0.5 1981 RSA Krugerrand gold 0.1 1986 PRC Panda silver 1 1986 USA Liberty dollar gold 0.25 1986 USA Liberty... (3 Replies)
Discussion started by: Ramesh M
3 Replies

7. Shell Programming and Scripting

Get the min avg and max with awk

aaa: 3 ms aaa: 2 ms aaa: 5 ms aaa: 10 ms .......... to get the 3 2 5 10 ...'s min avg and max something like min: 2 ms avg: 5 ms max: 10 ms (2 Replies)
Discussion started by: yanglei_fage
2 Replies

8. UNIX for Dummies Questions & Answers

Show 'All Files' If all file can find.

fileset='APP11.txt APP12.txt SPACEDB11.txt WEB11.txt WEB12.txt' Hi there, Give the fileset, if I can use grep to find all the files. How do I show: All Servers: instead of APP11.txt: APP12.txt: SPACEDB11.txt: WEB11.txt: WEB12.txt: (6 Replies)
Discussion started by: alvinoo
6 Replies

9. Shell Programming and Scripting

Execute command and show result in web page

Hi everyone, I have two question 1- I want to execute command in shell and after execution result show in a web server. (kind of making UI ) e.g. in shell root ~: show list item1 item2 item(n)in web server in a page draw a table and show those items in itno | name... (1 Reply)
Discussion started by: indeed_1
1 Replies

10. Shell Programming and Scripting

When comparing binary files, show human readable result?

Hello. I am comparing two binary file. The first file is the source file. The second file is a modified version of the first one. Modification concern uuid value. Example first file have multiple occurrences of 69a3604b-ac2b-43b7-af84-0a4a67fc6962 second file have the same occurence... (1 Reply)
Discussion started by: jcdole
1 Replies
GPIV_S-AVG(1)						      General Commands Manual						     GPIV_S-AVG(1)

NAME
gpiv_s-avg - Spatial statistics of PIV data. SYNOPSIS
gpiv_s-avg [-h | --help] [-p | --print] [-s] [-no_s] [-v | --version] [filename] < stdin > stdout DESCRIPTION
gpiv_s-avg reports the spatial global mean velocities and variances in x and y-direction of a PIV data stream. Only input data of which the peak number is not equal to -1 are taken into account. The parameters read from the configuration resources (containing the key POST) may be overruled by the command line options, as explained below. Options -h | --help On-line help. -p | --print Prints parameters, command line options and input and eventually filenames to stdout. The output is identic of filename.par, in case -f is used. -s Subtracts the mean x-and y-particle displacements from the input data. -no_s Suppresses subtracting the mean values from the input data. -v | --version Prints version information on standard output, then exits successfully. [-z dx0 dy0] zero offset of displacement or velocity estimators. filename Input PIV file. Overrides stdin and stdout. The output will be written to filename.sa.piv. Parameters are stored in filename.par and may be used for future use by including them in ./gpivrc. SEE ALSO gpivtools NOTES
AUTHOR
Gerber Van der Graaf BUGS
The program has been tested for PIV data. So far, no bugs have been found. 8 November 2006 GPIV_S-AVG(1)
All times are GMT -4. The time now is 04:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy