How to add the number of events grouped by field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to add the number of events grouped by field
# 1  
Old 07-21-2010
How to add the number of events grouped by field

Help i need to add to the end of the line the number of event grouped by id, my input file:

IN FILE:
ID DATE
10123 01-04-2008
10123 06-05-2008
10123 01-09-2009
10123 11-12-2009
10345 01-22-2008
10345 06-15-2008
10127 02-22-2010

OUT FILE:
ID DATE EVENT_NUMBER
10123 01-04-2008 1
10123 06-05-2008 2
10123 01-09-2009 3
10123 11-12-2009 4
10345 01-22-2008 1
10345 06-15-2008 2
10127 02-22-2010 1

Thanks in advance for your help.
# 2  
Old 07-21-2010
Try this:
Code:
awk '{print $0 FS a[$1]++ +1}' file

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 07-21-2010
Thank you very much it worked to perfection
# 4  
Old 07-21-2010
Code:
awk '{print $0, ++a[$1]}' urfile

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

2. Shell Programming and Scripting

Adding total of first field for each number in the second field

Dears, I need a script or command which can find the unique number from the second filed and against that number it adds the total of first field . 17215630 , 0 907043 ,1 201050 ,10 394149 ,4 1964 ,9 17215630, 0 907043 ,1 201050, 10 394149 ,4 1964 ,9 1234234, 55 23 ,100 33 ,67 ... (2 Replies)
Discussion started by: shary
2 Replies

3. Shell Programming and Scripting

awk field equal something, then add something to the field

Hi Everyone, a.txt a b c 1 e e e e e a b c 2 e e e e e the output is a b c 1 e e e e e a 00b c 2 e e e e e when 4th field = '2', then add '00' in the front of 2nd field value. Thanks (9 Replies)
Discussion started by: jimmy_y
9 Replies

4. Shell Programming and Scripting

Count number of occurences of a character in a field defined by the character in another field

Hello, I have a text file with n lines in the following format (9 column fields): Example: contig00012 149606 G C 49 68 60 18 c$cccccacccccccccc^c I need to count the number of lower-case and upper-case occurences in column 9, respectively, of the... (3 Replies)
Discussion started by: s052866
3 Replies

5. Shell Programming and Scripting

Sorting on two fields time field and number field

Hi, I have a file that has data in it that says 00:01:48.233 1212 00:01:56.233 345 00:09:01.221 5678 00:12:23.321 93444 The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies

6. UNIX for Dummies Questions & Answers

Number Grouped Rows in File

I have a file containing 750,000 records and have managed to sort them by related columns and now i'd like to add an ID number to the front of each line of the records that are grouped together. Which probably makes no sense so i have provided some example data and desired result. Given data.txt... (2 Replies)
Discussion started by: RacerX
2 Replies

7. Shell Programming and Scripting

add increment field when first field changes

Hi I have a file that looks like the following: Name1 aaa bbbb Name1 ffd hhghg Name1 dffg ghhhh Name2 rtrt dfff Name2 rrtfr tgtt Name2 dsddf gfggf Name2 ffffg gfgf NAme3 fdff ghhgh Is it possible to format it so that a number... (2 Replies)
Discussion started by: azekry
2 Replies
Login or Register to Ask a Question