Re: Awk Array Question



On Aug 30, 2:10 pm, Hermann Peifer <pei...@xxxxxx> wrote:
AyOut wrote:
I have a shell script that invokes an awk command on a file of the
following format:
(Date, Time)
2007-01-01, 00:00:00,121
2007-01-01, 00:00:00,311
2007-01-01, 00:00:00,432
...
...
2007-01-01, 00:01:10,778
2007-01-01, 00:01:10,981
2007-01-01, 00:01:11,121
...
...

The script I have basically parses the file and generates a comma
separated output of
Date, Time, Count
2007-01-01, 00:00:00, 3
2007-01-01, 00:01:10, 2
2007-01-01, 00:01:11, 1

The command looks like this:

awk '{++hr[$1,substr($2,1,9)]}END{for(item in hr)printf("%s%s\n",item,
hr[item])}' ${logfile} > ${logfile}.csv

At the end of the process I have an output of 86400 lines, too big for
Excel. I want to truncate the output to only output the max value in
any given minute and thus reduce the output to 1440 lines.

Try with substr($2,1,5)] instead of substr($2,1,9)].

Hermann


I thought about doing this, but that's only going to give me TPS
granularity at a minute level. Doing $2,1,9 allows me to capture the
hits per second. I.e.:
(counts)
22
23
20
...
...
22
24
21

The max second value for the above given minute would be 24.

.



Relevant Pages

  • Re: Reducing log size
    ... Truncate did not work since it keeps to top portion of ... # Get the number of lines in the logfile ... and then use splice or an explicit loop to copy the lines. ... Tie::File will handle locating and caching the locations of the ...
    (comp.lang.perl.misc)
  • Re: When exporting to excel, field will not exceed 255 characters.
    ... Since Excel 97, you can have up to 32,767 characters in a cell, ... When You Export an Access Report the Memo Field Is Truncated ... Formatted Memo Field Appears to Truncate Data After 255 ...
    (microsoft.public.access.externaldata)
  • Re: How do I return the lowest value of three other fields?
    ... By the way, in Excel, you could just use the Min function to pull the lowest ... "KARL DEWEY" wrote: ... But if the numbers differ, ... I'd use the "Truncate" function on the mean value (but even ...
    (microsoft.public.access.forms)
  • Re: When exporting to excel, field will not exceed 255 characters.
    ... Since Excel 97, you can have up to 32,767 characters in a cell, ... When You Export an Access Report the Memo Field Is Truncated ... Formatted Memo Field Appears to Truncate Data After 255 ...
    (microsoft.public.access.externaldata)
  • Problem with TransferSpreadsheet - memo fiedl gets truncated
    ... Access: 2002, SP3 ... Excel: 2002, SP3 ... indicating a truncate error with the memo field. ...
    (microsoft.public.access.modulesdaovba)