awk group by


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk group by
# 1  
Old 05-19-2009
Hammer & Screwdriver awk group by

Hi
I have a file in this format:
...
04/May/2009 16
04/May/2009 1
05/May/2009 3
05/May/2009 5
06/May/2009 1
06/May/2009 3
...

I need to sum for every day, What is the best way?
Thanks all
# 2  
Old 05-19-2009
Use gawk, nawk or /usr/xpg4/bin/awk on Solaris.

Code:
awk 'END{for(d in _)print d, _[d]}{_[$1]+=$2}' infile

# 3  
Old 05-19-2009
Code:
 awk '{a[$1]=a[$1]+$2}END{for(i in a)print i,a[i]}' file



-Devaraj Takhellambam
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Group and search using awk

file: Data has to be grouped on 1st field; And in each group, print 2nd field IF 1st field doesn't match with any of the values in 2nd field.. o/p to be: I ended up writing as below, any help ?? awk -F, '!($1 in a){a++;}END{for (i in a)print i}' file (3 Replies)
Discussion started by: JSKOBS
3 Replies

2. Shell Programming and Scripting

Awk: get upper and lower bound per group

Hi all, I've data as: 22 51018157 51018157 exonic CHKB nonsynonymous SNV 22 51018204 51018204 exonic CHKB nonsynonymous SNV 22 51018428 51018428 exonic CHKB nonsynonymous SNV 22 51018814 51018814 ... (4 Replies)
Discussion started by: genome
4 Replies

3. Shell Programming and Scripting

How to add using awk command for a group?

hi all below is the input file contains a code followed by amount input file 345,5.86 346,20.58 399,10.00 400,12.00 i need the output in the following way outputfile totalsumof345and346,26.44 totalsumof399and400,22.00 (10 Replies)
Discussion started by: hemanthsaikumar
10 Replies

4. Shell Programming and Scripting

awk Group By and count string occurrences

Hi Gurus, I'm scratching my head over and over and couldn't find the the right way to compose this AWK properly - PLEASE HELP :confused: Input: c,d,e,CLICK a,b,c,CLICK a,b,c,CONV c,d,e,CLICK a,b,c,CLICK a,b,c,CLICK a,b,c,CONV b,c,d,CLICK c,d,e,CLICK c,d,e,CLICK b,c,d,CONV... (6 Replies)
Discussion started by: Royi
6 Replies

5. Shell Programming and Scripting

awk - how do i get the last row of a group

How do i print the last record of a group in a file ? For example, I have a file like this : cat txt cucm1,location1,1,2,3 cucm2,location1,3,4,5 cucm1,location1,10,20,30 cucm2,location2,30,40,50 I am expecting a command that would print the last record of the group. For example, ... (2 Replies)
Discussion started by: Lakshmikumari
2 Replies

6. Shell Programming and Scripting

Awk-using group function

Hi, I have file with below format and sample data - File is pipe delimited Col1|col2|Account|Bal1|Bal2 1|2|1|10|5 1|2|2|10|2 1|3|3|10|3 I want output as SUM|1|2|2|20|7 SUM|1|3|1|10|3 Can anyone give me awk command (4 Replies)
Discussion started by: sanranad
4 Replies

7. Shell Programming and Scripting

Group by using awk

Hi All, I have a file in the following format... ***************************************************** 11/10/27 12:09 : Input Record 11/10/27 12:10 : Input Record 11/10/27 12:10 : Input Record 11/10/27 12:10 : Input Record 11/10/27 12:10 : Input Record 11/10/27 12:10 : Input... (2 Replies)
Discussion started by: sraj142
2 Replies

8. Infrastructure Monitoring

Processing records as group - awk

I have a file has following records policy glb id 1233 name Permit ping from "One" to "Second" "Address1" "Any" "ICMP-ANY" permit policy id 999251 service "snmp-udp" exit policy glb id 1234 name Permit telnet from "One" to "Second" "Address2" "Any" "TCP-ANY" permit policy id 1234... (3 Replies)
Discussion started by: baskar
3 Replies

9. Shell Programming and Scripting

Awk-Group count of field

Hi, Suppose if i am having a file with following records as given below. 5555 6756 5555 4555 4555 6767 how can i get the count of each record using AWK. Eg:5555 count should be 2 4555 count should be 2 6767 count should be 1 ... (5 Replies)
Discussion started by: tinivt
5 Replies

10. Shell Programming and Scripting

awk help required to group output and print a part of group line and original line

Hi, Need awk help to group and print lines to format the output as shown below INPUT FORMAT set echo on set heading on set spool on /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5;... (5 Replies)
Discussion started by: rajan_san
5 Replies
Login or Register to Ask a Question