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,168537840
2009-08-01,19:04:39,19:17:16,321545923
2009-08-01,19:07:00,19:09:53,624757969
2009-08-01,19:07:35,19:09:45,275602323
2009-08-01,19:39:22,20:50:29,5665469256
2009-08-02,19:00:06,19:06:01,1386402864
2009-08-02,19:00:09,20:57:20,98241673
2009-08-02,19:00:10,19:02:30,519669461
2009-08-02,19:00:10,20:00:13,604466725
2009-08-02,19:00:20,19:38:34,189802392
2009-08-02,19:07:11,19:17:16,292963957
2009-08-02,19:15:41,19:16:36,83704532
2009-08-02,19:20:42,19:23:22,578206015
2009-08-03,19:00:09,19:03:20,1283766757
2009-08-03,19:00:10,19:06:39,1095627752
2009-08-03,19:00:12,20:43:39,80770993
2009-08-03,19:00:15,20:06:55,7632777428
2009-08-03,19:00:28,19:42:56,2143945407
2009-08-03,19:12:09,19:26:04,300927680
2009-08-03,19:26:11,19:28:48,560081633
2009-08-03,19:34:32,19:35:23,54324466
2009-08-04,19:00:08,19:06:48,1149345050
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?
by: CptArAbPosted on 2009-08-04 at 06:15:21ID: 25013325
Ok, but whats wrong with what you got? It seems to be exactly what you need, so what is the question?