Add up numbers for each day


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add up numbers for each day
# 1  
Old 02-01-2010
Add up numbers for each day

Hi guys,

Is there an easy way I can add up the numbers in column $4 when the day of the week in column $1 is equal? So in the end I want an aggregate total for each day. e.g. 01,12,2009 00000000032000
Code:
01,12,2009,0000000000002094
02,12,2009,0000000000002128
03,12,2009,0000000000002117
04,12,2009,0000000000002021
05,12,2009,0000000000001584
06,12,2009,0000000000001856
07,12,2009,0000000000002150
08,12,2009,0000000000002117
09,12,2009,0000000000002148
10,12,2009,0000000000002118
11,12,2009,0000000000002037
12,12,2009,0000000000001600
13,12,2009,0000000000001614
14,12,2009,0000000000002061
15,12,2009,0000000000002060
16,12,2009,0000000000002104
17,12,2009,0000000000002089
18,12,2009,0000000000002002
19,12,2009,0000000000001591
20,12,2009,0000000000001630
21,12,2009,0000000000002012
22,12,2009,0000000000002012
23,12,2009,0000000000001942
24,12,2009,0000000000001817
25,12,2009,0000000000001790
26,12,2009,0000000000001530
27,12,2009,0000000000001504
28,12,2009,0000000000001845
29,12,2009,0000000000001929
30,12,2009,0000000000001933
31,12,2009,0000000000001835
01,12,2009,0000000000002079
02,12,2009,0000000000002058
03,12,2009,0000000000002111
04,12,2009,0000000000001978
05,12,2009,0000000000001584
06,12,2009,0000000000001892
07,12,2009,0000000000002073
08,12,2009,0000000000002109
09,12,2009,0000000000002053
10,12,2009,0000000000002101
11,12,2009,0000000000001982
12,12,2009,0000000000001699
13,12,2009,0000000000001601
14,12,2009,0000000000002081
15,12,2009,0000000000002025
16,12,2009,0000000000002102
17,12,2009,0000000000002092
18,12,2009,0000000000002009
19,12,2009,0000000000001621
20,12,2009,0000000000001612
21,12,2009,0000000000001923
22,12,2009,0000000000002043
23,12,2009,0000000000001919
24,12,2009,0000000000001912
25,12,2009,0000000000001809
26,12,2009,0000000000001600
27,12,2009,0000000000001613
28,12,2009,0000000000001891
29,12,2009,0000000000001911
30,12,2009,0000000000001880
31,12,2009,0000000000001756
01,12,2009,0000000000002058
02,12,2009,0000000000002075
03,12,2009,0000000000002147
04,12,2009,0000000000002055
05,12,2009,0000000000001629
06,12,2009,0000000000001849
07,12,2009,0000000000002051
08,12,2009,0000000000002078
09,12,2009,0000000000002125
10,12,2009,0000000000002089
11,12,2009,0000000000002154
12,12,2009,0000000000001719
13,12,2009,0000000000001650
14,12,2009,0000000000002084
15,12,2009,0000000000002126
16,12,2009,0000000000002138
17,12,2009,0000000000002195
18,12,2009,0000000000002007
19,12,2009,0000000000001679
20,12,2009,0000000000001638
21,12,2009,0000000000002015
22,12,2009,0000000000002221
23,12,2009,0000000000001914
24,12,2009,0000000000001865
25,12,2009,0000000000001813
26,12,2009,0000000000001574
27,12,2009,0000000000001490
28,12,2009,0000000000001936
29,12,2009,0000000000001930
30,12,2009,0000000000001907
31,12,2009,0000000000001786
01,12,2009,0000000000002005
02,12,2009,0000000000002051
03,12,2009,0000000000002145
04,12,2009,0000000000001987
05,12,2009,0000000000001595
06,12,2009,0000000000001971
07,12,2009,0000000000002021
08,12,2009,0000000000002101
09,12,2009,0000000000002089
10,12,2009,0000000000002081
11,12,2009,0000000000002027
12,12,2009,0000000000001669
13,12,2009,0000000000001649
14,12,2009,0000000000002003
15,12,2009,0000000000002075
16,12,2009,0000000000002125
17,12,2009,0000000000002033
18,12,2009,0000000000001947
19,12,2009,0000000000001574
20,12,2009,0000000000001603
21,12,2009,0000000000002022
22,12,2009,0000000000002006
23,12,2009,0000000000001968
24,12,2009,0000000000001888
25,12,2009,0000000000001819
26,12,2009,0000000000001568
27,12,2009,0000000000001482
28,12,2009,0000000000001843
29,12,2009,0000000000001984
30,12,2009,0000000000001944
31,12,2009,0000000000001810
01,12,2009,0000000000002049
02,12,2009,0000000000002018
03,12,2009,0000000000002036
04,12,2009,0000000000002010
05,12,2009,0000000000001616
06,12,2009,0000000000001855
07,12,2009,0000000000002010
08,12,2009,0000000000002102
09,12,2009,0000000000002053
10,12,2009,0000000000002116
11,12,2009,0000000000002034
12,12,2009,0000000000001660
13,12,2009,0000000000001660
14,12,2009,0000000000002072
15,12,2009,0000000000002072
16,12,2009,0000000000002221
17,12,2009,0000000000002135
18,12,2009,0000000000002045
19,12,2009,0000000000001708
20,12,2009,0000000000001687
21,12,2009,0000000000002022
22,12,2009,0000000000001960
23,12,2009,0000000000001975
24,12,2009,0000000000001891
25,12,2009,0000000000001827
26,12,2009,0000000000001579
27,12,2009,0000000000001510
28,12,2009,0000000000001912
29,12,2009,0000000000001964
30,12,2009,0000000000001934
31,12,2009,0000000000001893


Last edited by Scott; 02-01-2010 at 02:38 PM..
# 2  
Old 02-01-2010
Code:
awk -F"," ' { a[$1 FS $2 FS $3 FS]+=$4 } END  { for(i in a) { printf("%s%016d\n" , i , a[i]) }} ' file

# 3  
Old 02-01-2010
Code:
awk -F, '
  { S[$1 "." $2 "." $3 ]+=$4 }
  END { for( s in S )
    print s, S[s]
  }
' file1 | sort -nk1

# 4  
Old 02-01-2010
really good guys thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add day of week at the end of each line that shows the date?

I have a file that looks like: file1: www_blank_com 20121008153552 www_blank_com 20121008162542 www_blank_com 20121009040540 www_blank_com 20121009041542 www_blank_com 20121010113548 www_blank_com 20121011113551 www_blank_com 20121012113542 I want the new file to show the day of... (3 Replies)
Discussion started by: castrojc
3 Replies

2. UNIX for Dummies Questions & Answers

Move the files between Current day & a previous day

Hi All, I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day. i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.... (2 Replies)
Discussion started by: dsfreddie
2 Replies

3. Shell Programming and Scripting

script to find filenames with latest version and for all seq. numbers in a day

Hi, We have a requirement to find the set of filenames from the group of files in a specified folder based on (i) version number (ii) sequence number such that, for any given sequence number in a day only the latest version filenames have to indentified. Below is the format of... (4 Replies)
Discussion started by: Deepakbabu
4 Replies

4. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

5. UNIX for Dummies Questions & Answers

how can i add two numbers

hi, i am having one file which looks like the one below: ABC1 *** 1 4 ABC2 *** 7 12 ABC3 *** 0 34 ... (4 Replies)
Discussion started by: kripssmart
4 Replies

6. UNIX for Dummies Questions & Answers

Add a day to a given date

Hi, I have a date field which is a variable field being passed to the script from outside. I need to know how i can add 1 day to it. I have seen example of date subtraction but while adding each time date reaches 31 or 30 i have to put if else condition. Or for leap year also. Kindly let... (4 Replies)
Discussion started by: pallet
4 Replies

7. Shell Programming and Scripting

How to add numbers

Hello. I new to Shell Scripting. I have a file and here is the output of the file. 1.1M 1.1M 3.3M 149K 61K 75K 144K 135K 82K 170K 327K 2.0M 219K 165K (8 Replies)
Discussion started by: email-lalit
8 Replies

8. Shell Programming and Scripting

Write a shell script to find whether the first day of the month is a working day

Hi , I am relatively new to unix... Can u pls help me out to find out if the first day of the month is a working day ie from (Monday to Friday)...using Date and If clause in Korn shell.. This is very urgent. Thanks for ur help... (7 Replies)
Discussion started by: phani
7 Replies

9. Shell Programming and Scripting

How to add numbers?

:confused: I have plain text file "tmp" which include a range of numbers(bytes), say like: 123 234 567 2434 2323 213123 How can I add them and display out. should I use AWK, then how? I am a newer in Bourne shell, please give me a hand, thanks a lot (7 Replies)
Discussion started by: pnxi
7 Replies

10. Shell Programming and Scripting

Add some numbers!

im using this command to return the number of links in my directory, grep -c -i -h "href" *html */*html *htm *shtml is there a way of adding these to get the total? Cheers (3 Replies)
Discussion started by: TalkShowHost
3 Replies
Login or Register to Ask a Question