[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

08/04/2009 at 06:04AM PDT, ID: 24624445
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7

awk a file of dates, timestamps, values

Asked by mateinone in KornShell (ksh), Bourne-Again Shell (bash)

Tags: awk, shell, unix

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?
[+][-]08/04/09 06:15 AM, ID: 25013325

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/04/09 06:27 AM, ID: 25013464

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/04/09 06:39 AM, ID: 25013617

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/05/09 09:38 AM, ID: 25025298

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/06/09 12:26 AM, ID: 25030859

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/06/09 02:25 AM, ID: 25031395

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/06/09 05:43 AM, ID: 25032557

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/06/09 09:39 AM, ID: 25035413

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/07/09 01:38 AM, ID: 25040789

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: KornShell (ksh), Bourne-Again Shell (bash)
Tags: awk, shell, unix
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 3
Solution Grade: A
 
 
[+][-]08/17/09 07:12 AM, ID: 25114597

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625