For Programmers: Free Programming Magazines  


Home > Archive > AWK > May 2005 > Need a one liner or maybe more...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Need a one liner or maybe more...
Benz

2005-05-06, 8:55 am

This must be a simple one...

I need to find the count of lines falling into specific dates in a .dat
file dynamically. (ie) for each unique date (Y/M/D excluding time) it
should give out totals.

This is how the file will look:

0|3|2005/05/01 23:10:49||733422094
0|3|2005/05/01 23:47:23||733823935
0|3|2005/05/02 04:03:45||734677852
0|5|2005/05/02 00:01:27||715880879
0|3|2005/05/01 23:41:01||734394379
0|3|2005/05/01 23:46:27||733823935
0|2|2005/05/02 05:12:24||733091614
0|3|2005/05/01 23:47:56||733823935

In this case I need the output to display
2005/05/01 5
2005/05/02 3

| - is the field seperator.

Let me know if anybody has any scripts handy.

Thx Rex

Ed Morton

2005-05-06, 8:55 am



Benz wrote:
> This must be a simple one...
>
> I need to find the count of lines falling into specific dates in a .dat
> file dynamically. (ie) for each unique date (Y/M/D excluding time) it
> should give out totals.
>
> This is how the file will look:
>
> 0|3|2005/05/01 23:10:49||733422094
> 0|3|2005/05/01 23:47:23||733823935
> 0|3|2005/05/02 04:03:45||734677852
> 0|5|2005/05/02 00:01:27||715880879
> 0|3|2005/05/01 23:41:01||734394379
> 0|3|2005/05/01 23:46:27||733823935
> 0|2|2005/05/02 05:12:24||733091614
> 0|3|2005/05/01 23:47:56||733823935
>
> In this case I need the output to display
> 2005/05/01 5
> 2005/05/02 3
>
> | - is the field seperator.
>
> Let me know if anybody has any scripts handy.
>
> Thx Rex
>

gawk -F"[| ]" '{c[$3]++}END{for (d in c) print d, c[d]}'

Ed.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com