Help with Display Shell Script for date

hi friends,
I am working on extracting data from sar logs for analysis.

What is want to do is insert the date. The way i am doing is incrementing the date if i see the hour gets reduced (i.e. from 23 hours to 00 hours). Somehow the script which i have made is not able to handle the logic w.r.t 0.
Can you please suggest where i am going wrong /provide alternate scripting suggestion?

Below is the source file

> cat tt1
00:52:32,disk2000,0.01,0.50,0,0,0.00,1.31
00:52:32,disk2001,0.00,0.50,0,0,0.00,0.53
00:52:32,disk2003,0.00,0.50,0,0,0.00,0.78
00:52:32,disk2008,0.02,0.50,0,0,0.00,5.85
01:01:59,disk30,2.57,14.58,8,125,38.78,11.19
01:01:59,disk50,2.96,13.54,9,131,36.71,11.47
01:01:59,disk745,0.00,0.50,0,0,0.00,0.66
01:01:59,disk746,0.02,0.50,0,0,0.00,10.58
01:01:59,disk747,0.02,0.50,0,0,0.00,9.47

What I want is below output:

09-05-12 00:52:32,disk2000,0.01,0.50,0,0,0.00,1.31
09-05-12 00:52:32,disk2001,0.00,0.50,0,0,0.00,0.53
09-05-12 00:52:32,disk2003,0.00,0.50,0,0,0.00,0.78
09-05-12 00:52:32,disk2008,0.02,0.50,0,0,0.00,5.85
10-05-12 01:01:59,disk30,2.57,14.58,8,125,38.78,11.19
10-05-12 01:01:59,disk50,2.96,13.54,9,131,36.71,11.47
10-05-12 01:01:59,disk745,0.00,0.50,0,0,0.00,0.66
10-05-12 01:01:59,disk746,0.02,0.50,0,0,0.00,10.58
10-05-12 01:01:59,disk747,0.02,0.50,0,0,0.00,9.47

What i am getting is:

> ksh a3
10-05-12 00:52:32,disk2000,0.01,0.50,0,0,0.00,1.31
10-05-12 00:52:32,disk2001,0.00,0.50,0,0,0.00,0.53
10-05-12 00:52:32,disk2003,0.00,0.50,0,0,0.00,0.78
10-05-12 00:52:32,disk2008,0.02,0.50,0,0,0.00,5.85
09-05-12 01:01:59,disk30,2.57,14.58,8,125,38.78,11.19
09-05-12 01:01:59,disk50,2.96,13.54,9,131,36.71,11.47
09-05-12 01:01:59,disk745,0.00,0.50,0,0,0.00,0.66
09-05-12 01:01:59,disk746,0.02,0.50,0,0,0.00,10.58
09-05-12 01:01:59,disk747,0.02,0.50,0,0,0.00,9.47

The content of my script is:

> cat a3
#!/usr/bin/ksh
d='05/09/12'
mm=${d%??????}
yy=${d#??????}
dd1=${d%???}
ddx=${dd1#???}
awk -v dd="$ddx" -v mm="$mm" -v yy="$yy" -F":" '{a=$1;} {print ($1 < $a && $a !=0)   ?  dd + 1 "-" mm "-" yy " " $0 : dd "-" mm "-" yy " " $0}'  tt1

I know my logic to input the date in the output is dirty , but atleast it should get me started :)..

Thanks,
Kunwar

Try this:

awk -v dd="$ddx" -v mm="$mm" -v yy="$yy" -F":" '{print ((a&&$1<a)?++dd:dd) "-" mm "-" yy " " $0} {a=$1}'  tt1

Question: What happens on the 28th Feb?

Thanks Chuber it works.

---------- Post updated at 11:22 PM ---------- Previous update was at 11:14 PM ----------

hi Chuber,
Regarding 28th Feb i am still thinking..
One question (a&&$1<a) i didnt understand the functioning of 'a' before the '&&' can u plz explain. If it is 1 (meaning true) then it is obvious , but if it is any other value how does it still make it true?

any non-zero/null value equates to true, so this test can be thought of as does a exist and is greater than zero.
Which comming to think of it will stop 0 flagging a change of date - ($1<a) is probably best here, as no hour should have a value less than 0 anyway.

another safe test might be (length(a)&&$1<a)

1 Like