awk sed perl??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk sed perl??
# 1  
Old 10-28-2011
Data awk sed perl??

Hi guys

First of all a salute to this wonderful platform which has helped me many a times. Im now faced with something that I cannot solve.

I have data like this

Code:
11:14:18 0.46975
11:14:18 0.07558
11:14:18 0.00020
11:14:18 0.00120
11:14:18 0.25879
11:14:19 0.00974
11:14:19 0.05656
11:14:19 0.00030
11:14:19 0.00639
11:14:19 0.01767
11:14:19 0.00215

I need to count the number of times the event happens every second. Here is an ex output
Code:
11:14:18 5
11:14:19 6

The first column is a time scale, so i need it to go till 60 then increment the minute count, and once minutes is 60 increment the hour count.

Someone please help me out here Smilie

Last edited by radoulov; 10-28-2011 at 07:31 AM.. Reason: Code tags!
# 2  
Old 10-28-2011
Code:
uniq -c -w8 infile

EDIT: Although you might need to filter the output, come to think of it.

An awk alternative:
Code:
awk '{counts[$1]++} END {for (i in counts) {print i, counts[i]}}' infile


Last edited by CarloM; 10-28-2011 at 07:31 AM..
# 3  
Old 10-28-2011
wow! thanks. perfect Smilie
# 4  
Old 10-28-2011
Code:
 
perl -lane '$a{$F[0]}++}{foreach (keys %a){print "$_  $a{$_}"}' input

# 5  
Old 10-28-2011
Hi getmmg
The perl script threw output in random order, any way to have it in the same order as in input?

Thanks Smilie

---------- Post updated at 11:35 AM ---------- Previous update was at 11:33 AM ----------

Hi,
could you tell me which among these two you think would be faster?? I have to run this on a huge data set.
# 6  
Old 10-28-2011
Time them! Put a subset of the data (500K lines or whatever) in a file and run them on that with time at the start of the command (e.g. time uniq -c -w8 file > /dev/null).

fwiw, awk seems to run fastest on my system on a random file - but that probably has the same issue with output order.
# 7  
Old 10-28-2011
Code:
$ nawk '{print $1|"sort|uniq -c"}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace my perl with awk or sed

My code below will print only the email address from all lines. I want to convert it with sed or awk.. also what if i just want to find only filenames. cat LIS_EMAIL | perl -wne'while(/+@+\w+/g){print "$&\n"}' Hoping to extract the filename such us .exe, .bin. From file that has scrambled... (8 Replies)
Discussion started by: invinzin21
8 Replies

2. Shell Programming and Scripting

Searching and printing the only pattern using awk,sed or perl

Hi All, i have an output of command vmstat as below : $ vmstat System configuration: lcpu=4 mem=5376MB ent=1.00 kthr memory page faults cpu ----- ----------- ------------------------ ------------ ----------------------- r b avm fre re pi... (10 Replies)
Discussion started by: omkar.jadhav
10 Replies

3. Shell Programming and Scripting

Modify the file with awk,sed or perl

Hi All, I need help from any of you.Would be so thankful for your help. I/P DDDD,1045,161,1557,429,1694,800,1911,1113,2460,1457,2917> 1609,3113,1869,3317,2732,3701,3727,4132,5857,5107> 9004,6496 DDDD,1125,157,1558,429,1694,800,1911,1117,2432,1444,2906>... (2 Replies)
Discussion started by: Indra2011
2 Replies

4. Shell Programming and Scripting

SED/AWK maybe PERL in a WHILE loop

Hi, I have a file containing numerous string values, for example: AMFU8849636 CCLU7120334 GESU5784065 TEMU3070096I have a second file with multiple records, such as the one below that I would like to manipulate based on the strings from the first file: CATOS2EDI DSTOW ABC ... (7 Replies)
Discussion started by: doza22
7 Replies

5. Shell Programming and Scripting

Advance search using sed/awk/perl

Hi, I have a file with more than 50,000 lines of records and each record is 50 bytes in length. I need to search every record in this file between positions 11-19 (9 bytes) and 32-40 (9 bytes) and in case any of the above 2 fields is alpha-numeric, i need to replace the whole 9 bytes of that... (7 Replies)
Discussion started by: kikionline
7 Replies

6. Shell Programming and Scripting

Deleting characters with sed,perl,awk

Input: :: gstreamer :: xine-lib :: xine-lib-extras Output should be: gstreamer xine-lib xine-lib-extras How can it be done with sed or perl? (12 Replies)
Discussion started by: cola
12 Replies

7. Shell Programming and Scripting

Deleting the first column with sed,awk or perl

336 brtr 256 hello Output: brtr hello How can i do this with sed,awk or perl? (5 Replies)
Discussion started by: cola
5 Replies

8. Shell Programming and Scripting

Getting the first word using sed,awk or perl

Input: root:x:0: daemon:x:1: bin:x:2: sys:x:3: adm:x:4: tty:x:5: disk:x:6: lp:x:7: mail:x:8: Output: root daemon bin sys adm tty (8 Replies)
Discussion started by: cola
8 Replies

9. Shell Programming and Scripting

How to remove spaces using awk,sed,perl?

Input: 3456 565 656 878 235 8 4 8787 3 7 35 878 Expected output: 3456 565 656 878 235 8 4 8787 3 7 35 878 How can i do this with awk,sed and perl? (10 Replies)
Discussion started by: cola
10 Replies

10. Shell Programming and Scripting

Question related to sed or awk or perl

Hi All, I have a big file of 100,000 lines with the following format: 1,736870,736870,1,2,5,547,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445 1,881246,881246,1,2,6,402,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445... (4 Replies)
Discussion started by: toms
4 Replies
Login or Register to Ask a Question