how to make an average value every 128lines?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to make an average value every 128lines?
# 1  
Old 01-14-2009
how to make an average value every 128lines?

hi!
i have a 8192 lines file like this ( the time will not change)

12:43:17 -69 -
12:43:17 -66 -
12:43:17 -71 -
12:43:17 -71 -
12:43:17 -70 -
12:43:17 -66 -
12:43:17 -70 -
12:43:17 -66 -
12:43:17 -71 -
12:43:17 -71 -
12:43:17 -67 -
12:43:17 -69 -
12:43:17 -69 -
12:43:17 -66 -
it's too big to threat so i have to an average of the 2nd column every 128 lines?
the final file will contain 64 lines like this
12:43:17 average of the 1st 128lines
12:43:17 average of the 2nd 128lines

thank you
# 2  
Old 01-14-2009
Try something like this:
Code:
awk -F'-' '{ sum += $2 ; if( NR%128 == 0) { print $1, sum/128; sum = 0 } }' filename

# 3  
Old 01-14-2009
thank you!
it works!
but at the end of the lines, i have a 0
in example:
12:43:17 -68 - 0
12:43:17 -66 - 0
12:43:17 -67 - 0
12:43:17 -69 - 0
12:43:17 -66 - 0
12:43:17 -67 - 0
12:43:17 -69 - 0
12:43:17 -67 - 0

and of course, i don't want it..
is there any possibility?
if not, i will do another awk script to delete it
thank you again
# 4  
Old 01-14-2009
The last 0 doesn't affect the code output. Then whats the problem ?
# 5  
Old 01-14-2009
i think i have a problem with my code.

thank you for your help!!
# 6  
Old 01-14-2009
just replace a.txt with your file and assign $line to your number 128 or whatever, then below script should help you.

Code:
#!/usr/bin/perl
$line=8;
open FH,"<a.txt";
while(<FH>){
	my @tmp=split("-",$_);
	$n+=$tmp[1];
	if ( $. % $line == 0){
		print $tmp[0]," : ",$n/$line,"\n";
		$n=0;
	}
	$pre=$tmp[0] unless $pre;
}
print $pre," : ",$n/($. % $line) if $. % $line;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Calculating average

Hi I have file like below 111,victor,48,12,36 342,Peter,54,58,30 476,Scott,25,36,48 567,Patty,74,17,95 I have written below code to calcualte avereage for every id Victor = 48+12+36/3 #!/bin/ksh /usr/xpg4/bin/awk ' BEGIN {FS=","} {sum=0; n=0;i=3 (1 Reply)
Discussion started by: stew
1 Replies

2. Shell Programming and Scripting

Get column average using ID

I have a file that looks like this: id window BV 1 1 0.5 1 2 0.2 1 3 0.1 2 1 0.5 2 2 0.1 2 3 0.2 3 1 0.4 3 2 0.6 3 3 0.8 Using awk, how would I get the average BV for window 1? Output like this: window avgBV 1 0.47 2 0.23 (10 Replies)
Discussion started by: jwbucha
10 Replies

3. Shell Programming and Scripting

Average for every day

Hi i have data like - Fieldseperator is "\t" -.. ... 05/18/12-23:40 12.0647 96.4762 140.746 19.4222 38.0837 17.1549 05/18/12-23:50 11.9463 97.7457 139.447 20.4776 29.8511 17.0144 05/19/12-00:00 11.6922 94.7384 130.364 18.5693 28.28 15.6425 05/19/12-00:10 10.8512 87.547 113.844... (11 Replies)
Discussion started by: IMPe
11 Replies

4. Programming

Issue with make, no rule to make target etc.

I have been trying to split up my src directory to clear out files that are not re-compiled very often. Now I have the following setup in my trunk, trunk/bld trunk/src/ trunk/src/src_server trunk/makefile.linux In the make file, I have compile rules SOURCELOC = src # compile src c++... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

5. UNIX for Dummies Questions & Answers

Difference between configure/make/make install.

Hi, While installation of apache on linux, we perform the below tasks. 1) Untar 2) configure 3) make 4) make install. I wanted to understand the difference and working of configure/make/make install. Can any one help me understanding this? Thanks in advance. (1 Reply)
Discussion started by: praveen_b744
1 Replies

6. UNIX for Dummies Questions & Answers

How to make a make from other folder

Hi, Sorry for my English. I want Execute a make from other folder but no it's a normal make. The comand is: make telosb install,3 And for example if i have to execute this comand in /tmp and i am in /$HOME how he would be now the comand? thx (7 Replies)
Discussion started by: Grobix
7 Replies

7. Solaris

Gani Network Driver Won't Install - make: Fatal error: Don't know how to make targ...

I attached a README file that I will refer to. I successfully completed everything in the README file until step 4. # pwd /gani/gani-2.4.4 # ls COPYING Makefile.macros gem.c Makefile Makefile.sparc_gcc gem.h Makefile.amd64_gcc ... (1 Reply)
Discussion started by: Bradj47
1 Replies

8. Linux

Error in issuing a make and make install

Hi, Recently I install a package and try to do a make and make install. However, in the make it gives me below error:- make:Nothing to be done for 'install-exec-am' make:Nothing to be done for 'install-data-am' Can anyone please explain to me what does this mean? I have been trying... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

9. UNIX for Dummies Questions & Answers

average value

If I have a file like this, could anyone please guide me how to find the average value in each metrix. The file has got about 130,000 metrixs. Grid-ref= 142, 235 178 182 203 240 273 295 289 293 283 262 201 176 167 187 187 246 260 282 299 312 293 276 230 191 169 ... (2 Replies)
Discussion started by: su_in99
2 Replies

10. UNIX for Dummies Questions & Answers

make and make install commands

Hi there, I am installing a package at the moment on to my Solaris version 8 and I have run into a problem with the 'make' command. I have installed the package using the 'pkgadd' command and I am now at the stage where I have to use the 'make' command followed by the 'make install'... (4 Replies)
Discussion started by: gerwhelan
4 Replies
Login or Register to Ask a Question