Sum value in a row and print the max


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sum value in a row and print the max
# 1  
Old 12-03-2013
Sum value in a row and print the max

I have the input file in attached.

I want the output file :
Code:
Date , Time , Max_Bearer
11/01/2013 , 23:00 , 1447.894167
11/02/2013 , 00:00 , 1429.266667
11/03/2013 , 00:00 , 712.3175
11/04/2013 , 22:00 , 650.9533333
11/05/2013 , 23:00 , 665.9558333
11/06/2013 , 23:00 , 659.8616667
11/07/2013 , 23:00 , 658.26
11/08/2013 , 12:00 , 582.7608333
11/09/2013 , 22:00 , 575.7433333
11/10/2013 , 22:00 , 580.1966667
11/11/2013 , 21:00 , 561.8425
11/12/2013 , 22:00 , 573.9575
11/13/2013 , 20:00 , 598.265
11/14/2013 , 22:00 , 576.7808333
11/15/2013 , 13:00 , 585.7066667
11/16/2013 , 22:00 , 591.3466667
11/17/2013 , 22:00 , 590.0875
11/18/2013 , 22:00 , 589.975
11/19/2013 , 22:00 , 586.0625
11/20/2013 , 20:00 , 576.6925
11/21/2013 , 20:00 , 587.5325
11/22/2013 , 22:00 , 584.4366667
11/23/2013 , 22:00 , 587.0691667
11/24/2013 , 22:00 , 583.9275
11/25/2013 , 22:00 , 604.375
11/26/2013 , 22:00 , 614.1791667
11/27/2013 , 22:00 , 600.42
11/28/2013 , 22:00 , 591.69
11/29/2013 , 23:00 , 591.0058333
11/30/2013 , 22:00 , 597.6166667

the column 1 = date , 2 = hour for max value, 3 = total for the row in each hour

thanks,

Last edited by justbow; 12-04-2013 at 05:15 AM.. Reason: results on nov only
# 2  
Old 12-03-2013
Please, also, show your attempts at solving this and where you're stuck..
# 3  
Old 12-04-2013
Code:
grep 2 $@ | cut -d"," -f1 > 1
grep 2 $@ | cut -d"," -f2-6 | awk -F, '{sum=0; for(i=1;i<=NF;i++) sum=sum+$i; print sum}' > 2

paste -d" " 1 2 > 3
awk -F" " '
BEGIN {
        str="Date Time  Max_Bearer";
        max=0;
}
{
        #ti= $1 " " $2;
        if ( str !~ $1 ) {
                print str " , " hr " , "  max;
                max=0;
                hr=0;
                str = $1;
        }

        if ( max < $3 ) {
                max = $3;
                hr = $2;
        }
}
END {
                print str " , " hr " , " max;

}' 3

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print a row with the max number in a column

Hello, I have this table: chr1_16857_17742 - chr1 17369 17436 "ENST00000619216.1"; "MIR6859-1"; - 67 chr1_16857_17742 - chr1 14404 29570 "ENST00000488147.1"; "WASH7P"; - 885 chr1_16857_18061 - chr1 ... (5 Replies)
Discussion started by: coppuca
5 Replies

2. Shell Programming and Scripting

Sum of numbers in row

Need help in coding: File with several rows incl. numbers like 1 2 3 4 5 6 7 8 ... How can i build the sum of each row seperately? 10 26 ... Thx for help. Please use CODE tags as required by forum rules! (13 Replies)
Discussion started by: smitty11
13 Replies

3. Shell Programming and Scripting

Add sum of columns and max as new row

Hi, I am a new bie i need some help with respect to shell onliner; I have data in following format Name FromDate UntilDate Active Changed Touched Test 28-03-2013 28-03-2013 1 0.6667 100 Test2 28-03-2013 03-04-2013 ... (1 Reply)
Discussion started by: gangaraju6
1 Replies

4. Shell Programming and Scripting

Print row on 4th column to all row

Dear All, I have input : SEG901 5173 9005 5740 SEG902 5227 5284 SEG903 5284 5346 SEG904 5346 9010 SEG905 5400 5456 SEG906 5456 5511 SEG907 5511 9011 SEG908 5572 9015 SEG909 5622 9020 SEG910 5678 5739 SEG911 5739 5796 SEG912 5796 9025 ... (3 Replies)
Discussion started by: attila
3 Replies

5. Shell Programming and Scripting

Get row number from file1 and print that row of file2

Hi. How can we print those rows of file2 which are mentioned in file1. first character of file1 is a row number.. for eg file1 1:abc 3:ghi 6:pqr file2 a abc b def c ghi d jkl e mno f pqr ... (6 Replies)
Discussion started by: Abhiraj Singh
6 Replies

6. Shell Programming and Scripting

Identify max value in diff columns for same row

Hi, I have a file with 1M records ABC 200 400 2.4 5.6 ABC 410 299 12 1.5 XYZ 4 5 6 7 MNO 22 40 30 70 MNO 47 55 80 150 What I want is for all the rows it should take the max value where there are duplicates output ABC 410 400 12 5.6 XYZ 4 5 6 7 MNO 47 55 80 150 How can i... (6 Replies)
Discussion started by: Diya123
6 Replies

7. Shell Programming and Scripting

awk, max value, array, row

Hello: I want to print out the entire row with max value in column 3 based on column 2. Input file is millions rows. test.dat: Contig1 lcl|1DL 111 155 265 27 Contig2 lcl|1DS 100 73 172 100 Contig3 lcl|1DL 140 698 837 140 Contig3 lcl|6DS 107 1488 1594... (1 Reply)
Discussion started by: yifangt
1 Replies

8. Shell Programming and Scripting

Print sum and relative value of the sum

Hi i data looks like this: student 1 Subject1 45 55 Subject2 44 55 Subject3 33 44 // student 2 Subject1 45 55 Subject2 44 55 Subject3 33 44 i would like to sum $2, $3 (marks) and divide each entry in $2 and $3 with their respective sums and print for each student as $4 and... (2 Replies)
Discussion started by: saint2006
2 Replies

9. Shell Programming and Scripting

Sum of values coming in a row

Hi, my requirement is to sum values in a row. eg: input is: sum,value1,value2,value3,.....,value N Required Output: sum,<summation of N values> Please help me... (5 Replies)
Discussion started by: MrGopal666
5 Replies

10. Shell Programming and Scripting

How i get the max value of a row?

I have a file like: <word> 5 <word> 3 <word> 5 <word> 2 <word> 6 <word> 8 <word> 12 and i need to know the max value of the second column, in this case 12. Plz help me! Actually i need the TOTAL, AVERANGE and MAX VALUE and i'm using this in... (10 Replies)
Discussion started by: Lestat
10 Replies
Login or Register to Ask a Question