Awk total and variance


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk total and variance
# 1  
Old 04-03-2011
Awk total and variance

File1
Code:
 
0358 Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd    (M) RW  102413
0359 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
035A Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
035B Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
035C Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   27641
035D Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   27641
035E Not Visible            ***:* 09B:D10 2-WayMir     N/Grp'd       WD    8632
035F Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd        RW   30720
0360 Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   28665
0361 Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   29689
0362 Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd        RW   30713
0363 Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   46069
0364 Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   46069
0365 Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd    (M) RW  256031
0366 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0367 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0368 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0369 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
036A Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
036B Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
036C Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
036D Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
036E Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
03F7 Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd        RW   40950
0411 Not Visible            ***:*  NA:NA  TDEV          N/Grp'd  (M) RW  706562

File2
Code:
 
0358 Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd    (M) RW  102413
0359 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
035A Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
035B Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
035C Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   27641
035D Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   27641
035E Not Visible            ***:* 09B:D10 2-WayMir     N/Grp'd       WD    8632
035F Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd        RW   30720
0360 Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   28665
0361 Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   29689
0362 Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd        RW   30713
0363 Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   46069
0364 Not Visible            ???:?  NA:NA  BCV+TDEV      N/Asst'd     NR   46069
0365 Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd    (M) RW  256031
0366 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0367 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0368 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0369 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
036A Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
036B Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
036C Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
036D Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
036E Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
03F7 Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd        RW   40950
0411 Not Visible            ***:*  NA:NA  TDEV          N/Grp'd  (M) RW  706562
0416 Not Visible            ***:*  NA:NA  TDEV          N/Grp'd  (m) RW       -
041A Not Visible            ???:?  NA:NA  TDEV          N/Grp'd  (M) NR  102413
041B Not Visible            ???:?  NA:NA  TDEV          N/Grp'd  (m) NR       -
041C Not Visible            ???:?  NA:NA  TDEV          N/Grp'd  (m) NR       -
041D Not Visible            ???:?  NA:NA  TDEV          N/Grp'd  (m) NR       -
041E Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd        RW   40950
0456 Not Visible            ***:*  NA:NA  RDF1+TDEV     Grp'd    (M) RW  102413

Output
Code:
RDF1+TDEV  30 TB( +2%) 
2-WayMir   10 TB( -2%)
BCV+TDEV   15 TB( +0%)
TDEV       11 TB( +1%)

Output file is total in Terabytes rounded off ( last column of files is in MB ) , grouped by 6th field type and shows the variance rounded off ( % increase or decrease ) from file 1
If there is no change then 0%
Thx
# 2  
Old 04-03-2011
Try:
Code:
awk 'NR==FNR{a[$6]+=$NF}NR!=FNR{b[$6]+=$NF}END{for (i in a){printf "%s\t%.2f TB( %+d%)\n",i,b[i]/(1024*1024),(b[i]-a[i])/(a[i]*0.01)}}' file1 file2

# 3  
Old 04-03-2011
Thanks Bartus .... works fine
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk for total

Have a input file like this ..... attachments 100G shared 1T archive 300M documents 300G remotedocs 150M I need the total in GB's ... where as M=MB,G=GB,T=TB Basically need awk to calculate the total based on end... (5 Replies)
Discussion started by: greycells
5 Replies

2. Shell Programming and Scripting

AWK sample variance

I would like to calculate 1/n In awk, I wrote the following line for the sigma summation: { summ+=($1-average)^2 } Full code: BEGIN { Print "This script calculate error estimates"; sum=0 } { sum+=$1; n++ } END { average = sum/n } BEGIN { summ=0 } { summ+=($1-average)^2 } END { print... (8 Replies)
Discussion started by: chrisjorg
8 Replies

3. Shell Programming and Scripting

Calculating Running Variance Using Awk

Hi all, I am attempting to calculate a running variance for a file containing a column of numbers. I am using the formula variance=sum((x-mean(x))^2)/(n-1), where x is the value on the current row, and mean(x) is the average of all of the values up until that row. n represents the total number... (1 Reply)
Discussion started by: Jahn
1 Replies

4. Shell Programming and Scripting

Total Count using AWK

Hi Everybody, I have the following example file... 199|TST-GURGAON|GURGAON|1 199|TST-GURGAON|GURGAON|1 199|TST-GURGAON|GURGAON|1 199|TST-GURGAON|GURGAON|1 199|TST-GURGAON|GURGAON|1 199|TST-GURGAON|GURGAON|1 199|TST-GURGAON|GURGAON|1 199|TST-GURGAON|GURGAON|1 199|TST-GURGAON|GURGAON|1... (8 Replies)
Discussion started by: sraj142
8 Replies

5. Shell Programming and Scripting

How to get total time using awk

Hi guys, I can't find a solution to sum the h:m:s: columns. 28/05/2010 03h 29min 34seg ADSL TELEMAR 28/05/2010 12h 19min 21seg ADSL TELEMAR 29/05/2010 04h 20min 02seg ADSL TELEMAR 29/05/2010 04h 31min 45seg ADSL TELEMAR 30/05/2010 06h 10min 43seg ADSL TELEMAR Thanks Use code... (8 Replies)
Discussion started by: ashimada
8 Replies

6. Shell Programming and Scripting

awk total and print if

hi all! I have a space delimited file... I would like to total column 3 on the condition that column 2 is less than 1030 to a variable in my script something like this: TOTAL="`awk '{$2 < 1030} {s+=$3}END{print s}' file`" Seem to be ignoring the {$2 < 1030}, I'm not sure of the... (3 Replies)
Discussion started by: lyoncc
3 Replies

7. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

8. Programming

C language to calculate mean,variance

Here I want to calculate mean,variance and sum from a file 1.1*2*4*22*211*22*12*22*22*11 2.2*2*22*12*22*11*11*122*33*22 3.9*7*22*88*87*98*67*66*56*66*11 As this is a large file and i am trying to write in c where formulae of MEAN = 1/N (X1...+..Xn) Variance = square root of 1/N-1... (9 Replies)
Discussion started by: cdfd123
9 Replies

9. Shell Programming and Scripting

calculating variance in perl programming

#!/usr/bin/perl -w use strict; open(FH,"$ARGV") or die; my @temp=<FH>; close FH; my $mean = Mean(\@temp); my $var = variance(\@temp); print "$var\n"; sub estimate_variance { my ($arrayref) = @_; my ($mean,$result) = (mean($arrayref),0); foreach (@$arrayref) {... (4 Replies)
Discussion started by: cdfd123
4 Replies
Login or Register to Ask a Question