Okay so I have what i figure should be a fairly straight forward question, but I was wondering what the answer is so thought I would throw it up
I have a file with dates, times, times, bytes
here is an example
2009-08-01,19:00:24,19:31:
27,1685378
40
2009-08-01,19:04:39,19:17:
16,3215459
23
2009-08-01,19:07:00,19:09:
53,6247579
69
2009-08-01,19:07:35,19:09:
45,2756023
23
2009-08-01,19:39:22,20:50:
29,5665469
256
2009-08-02,19:00:06,19:06:
01,1386402
864
2009-08-02,19:00:09,20:57:
20,9824167
3
2009-08-02,19:00:10,19:02:
30,5196694
61
2009-08-02,19:00:10,20:00:
13,6044667
25
2009-08-02,19:00:20,19:38:
34,1898023
92
2009-08-02,19:07:11,19:17:
16,2929639
57
2009-08-02,19:15:41,19:16:
36,8370453
2
2009-08-02,19:20:42,19:23:
22,5782060
15
2009-08-03,19:00:09,19:03:
20,1283766
757
2009-08-03,19:00:10,19:06:
39,1095627
752
2009-08-03,19:00:12,20:43:
39,8077099
3
2009-08-03,19:00:15,20:06:
55,7632777
428
2009-08-03,19:00:28,19:42:
56,2143945
407
2009-08-03,19:12:09,19:26:
04,3009276
80
2009-08-03,19:26:11,19:28:
48,5600816
33
2009-08-03,19:34:32,19:35:
23,5432446
6
2009-08-04,19:00:08,19:06:
48,1149345
050
I want to get the output so that it grabs
Date, start, end, bytes (as mb)
for each date.
so the date, the earliest start time, the latest end time and the total sum of bytes for the day and I would like it in awk.
I can do it and do it quick with a simple shell
cat $filename |awk -F, '{print $1}'|sort -u |while read date
do
early=`cat $filename|grep "^$date"|awk -F, '{print $2}'|sort -n|head -n 1`
late=`cat $filename|grep "^$date"|awk -F, '{print $3}'|sort -n|tail -n 1`
sum=`cat $filename|awk -F, '/^'"$date"'/ {printf "%-.2f", ($4/1024/1024)}'|awk '{sum = sum + $1} END {print sum"Mb"}'`
echo date: $date early:$early late:$late sum:$sum
done
for the following output
date: 2009-07-29 early:19:00:06 late:21:14:06 sum:2445.09Mb
date: 2009-07-30 early:19:00:08 late:20:40:34 sum:205.491Mb
date: 2009-07-31 early:19:00:06 late:20:49:37 sum:146.324Mb
date: 2009-08-01 early:19:00:04 late:20:50:29 sum:1172.21Mb
date: 2009-08-02 early:19:00:06 late:20:57:20 sum:1322.19Mb
date: 2009-08-03 early:19:00:09 late:20:43:39 sum:1224.3Mb
date: 2009-08-04 early:19:00:08 late:21:09:29 sum:1096.1Mb
Anyone keen to give it a go?