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