Re: Text Proccessing script - advice?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Tue, Dec 21, 2010 at 08:30:43PM +0200, Roland RoLaNd wrote:

(chuckle) That's a bit more verbose than necessary. As a one-liner:

awk -F, '($4>"09:00:00"){c[$2 "," $3]++};END{for (i in c){print i "," c[i]}}' $filename

01368,2010-12-02,4
01368,2010-12-03,3

(You might check if you want >="09:00:00", and include the edge case.)

-F,                   # set separator to comma

                      # (automatic loop over all data lines)
($4>"09:00:00"){      # do if fourth field greater than 09:...
c[$2 "," $3]++        # increment hash element pointed to by
                      # second and third fields separated by comma
                      # (that is, hash on id,date)

END{                  # after finishing the data
for (i in c){         # for each observed hash value in array c
print i "," c[i]      # print the hash value, comma, count

-- 
  lundin@xxxxxxxx
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos


[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux