fsanchez13
Technical User
I was given this script by pmurray99, thank you very very much, below is the script and then below that is a small piece of the data I am using it on and then the Results. If you notice at the very top of the results it took the first line for 750 (which should be the 00:00:00 line) and placed it on the 22:00:00 line for 502. Then it did it again on the 22:00:00 line for 750 and put the first line for 800 as the 22:00:00 line. It does this the entire length of the data. Am I doing somthing wrong? sorry this is so long but I wanted to make sure that I had everything included.
#!/bin/ksh
integer TotMtu=mtu=0
integer TotUsg=usg=0
while read -- line
do
[[ -z $line ]] &&
continue
set -- $line
[[ $1 = Time ]] &&
{
print $line
continue
}
hour=${1%%:**}
mtu=$3
usg=$4
: ${savehour:=$hour}
[[ $hour = $savehour ]] ||
{
print "${savehour}:00:00" $2 $TotMtu $TotUsg $5 $6
TotMtu=$mtu
TotUsg=$usg
savehour=$hour
continue
}
(( TotMtu=TotMtu+mtu ))
(( TotUsg=TotUsg+usg ))
done < /export/home/fsanchez/capmove/test2.txt
print "${hour}:00:00" $2 $TotMtu $TotUsg $4 $5
DATA:
22:29:42 502 0 0 24 0
22:59:42 502 0 0 24 0
00:29:42 750 72 187 356 4
00:59:42 750 72 176 356 4
01:29:42 750 72 150 356 4
01:59:42 750 72 130 356 4
02:29:42 750 72 165 356 4
02:59:42 750 72 131 356 4
03:29:42 750 72 111 356 4
03:59:42 750 72 92 356 4
04:29:42 750 72 87 356 4
04:59:42 750 72 74 356 4
05:29:42 750 72 78 356 4
05:59:42 750 72 94 356 4
06:29:42 750 72 83 356 4
06:59:42 750 72 90 356 4
07:29:42 750 72 116 356 4
07:59:42 750 72 105 356 4
08:29:42 750 72 253 356 4
08:59:42 750 72 390 356 4
09:29:42 750 72 471 356 4
09:59:42 750 72 621 356 4
10:29:42 750 72 536 356 4
10:59:42 750 72 649 356 4
11:29:42 750 72 791 356 4
11:59:42 750 72 789 356 4
12:29:42 750 72 756 356 4
12:59:42 750 72 656 356 4
13:29:42 750 72 752 356 4
13:59:42 750 72 602 356 4
14:29:42 750 72 548 356 4
14:59:42 750 72 609 356 4
15:29:42 750 72 670 356 4
15:59:42 750 72 839 356 4
16:29:42 750 72 986 356 4
16:59:42 750 72 993 356 4
17:29:42 750 72 909 356 4
17:59:42 750 72 894 356 4
18:29:42 750 72 892 356 4
18:59:42 750 72 1031 356 4
19:29:42 750 72 1267 356 4
19:59:42 750 72 1636 356 4
20:29:42 750 72 1770 356 4
20:59:42 750 72 1786 356 4
21:29:42 750 72 1968 356 4
21:59:42 750 72 1899 356 4
22:29:42 750 72 1184 356 4
22:59:42 750 72 830 356 4
00:29:42 800 0 0 72 0
00:59:42 800 0 0 72 0
RESULTS:
20:00:00 502 0 0 24 0
21:00:00 502 0 0 24 0
22:00:00 750 0 0 356 4
00:00:00 750 144 363 356 4
01:00:00 750 144 280 356 4
02:00:00 750 144 296 356 4
03:00:00 750 144 203 356 4
04:00:00 750 144 161 356 4
05:00:00 750 144 172 356 4
06:00:00 750 144 173 356 4
07:00:00 750 144 221 356 4
08:00:00 750 144 643 356 4
09:00:00 750 144 1092 356 4
10:00:00 750 144 1185 356 4
11:00:00 750 144 1580 356 4
12:00:00 750 144 1412 356 4
13:00:00 750 144 1354 356 4
14:00:00 750 144 1157 356 4
15:00:00 750 144 1509 356 4
16:00:00 750 144 1979 356 4
17:00:00 750 144 1803 356 4
18:00:00 750 144 1923 356 4
19:00:00 750 144 2903 356 4
20:00:00 750 144 3556 356 4
21:00:00 750 144 3867 356 4
22:00:00 800 144 2014 72 0
00:00:00 800 0 0 72 0
01:00:00 800 0 0 72 0
02:00:00 800 0 0 72 0
#!/bin/ksh
integer TotMtu=mtu=0
integer TotUsg=usg=0
while read -- line
do
[[ -z $line ]] &&
continue
set -- $line
[[ $1 = Time ]] &&
{
print $line
continue
}
hour=${1%%:**}
mtu=$3
usg=$4
: ${savehour:=$hour}
[[ $hour = $savehour ]] ||
{
print "${savehour}:00:00" $2 $TotMtu $TotUsg $5 $6
TotMtu=$mtu
TotUsg=$usg
savehour=$hour
continue
}
(( TotMtu=TotMtu+mtu ))
(( TotUsg=TotUsg+usg ))
done < /export/home/fsanchez/capmove/test2.txt
print "${hour}:00:00" $2 $TotMtu $TotUsg $4 $5
DATA:
22:29:42 502 0 0 24 0
22:59:42 502 0 0 24 0
00:29:42 750 72 187 356 4
00:59:42 750 72 176 356 4
01:29:42 750 72 150 356 4
01:59:42 750 72 130 356 4
02:29:42 750 72 165 356 4
02:59:42 750 72 131 356 4
03:29:42 750 72 111 356 4
03:59:42 750 72 92 356 4
04:29:42 750 72 87 356 4
04:59:42 750 72 74 356 4
05:29:42 750 72 78 356 4
05:59:42 750 72 94 356 4
06:29:42 750 72 83 356 4
06:59:42 750 72 90 356 4
07:29:42 750 72 116 356 4
07:59:42 750 72 105 356 4
08:29:42 750 72 253 356 4
08:59:42 750 72 390 356 4
09:29:42 750 72 471 356 4
09:59:42 750 72 621 356 4
10:29:42 750 72 536 356 4
10:59:42 750 72 649 356 4
11:29:42 750 72 791 356 4
11:59:42 750 72 789 356 4
12:29:42 750 72 756 356 4
12:59:42 750 72 656 356 4
13:29:42 750 72 752 356 4
13:59:42 750 72 602 356 4
14:29:42 750 72 548 356 4
14:59:42 750 72 609 356 4
15:29:42 750 72 670 356 4
15:59:42 750 72 839 356 4
16:29:42 750 72 986 356 4
16:59:42 750 72 993 356 4
17:29:42 750 72 909 356 4
17:59:42 750 72 894 356 4
18:29:42 750 72 892 356 4
18:59:42 750 72 1031 356 4
19:29:42 750 72 1267 356 4
19:59:42 750 72 1636 356 4
20:29:42 750 72 1770 356 4
20:59:42 750 72 1786 356 4
21:29:42 750 72 1968 356 4
21:59:42 750 72 1899 356 4
22:29:42 750 72 1184 356 4
22:59:42 750 72 830 356 4
00:29:42 800 0 0 72 0
00:59:42 800 0 0 72 0
RESULTS:
20:00:00 502 0 0 24 0
21:00:00 502 0 0 24 0
22:00:00 750 0 0 356 4
00:00:00 750 144 363 356 4
01:00:00 750 144 280 356 4
02:00:00 750 144 296 356 4
03:00:00 750 144 203 356 4
04:00:00 750 144 161 356 4
05:00:00 750 144 172 356 4
06:00:00 750 144 173 356 4
07:00:00 750 144 221 356 4
08:00:00 750 144 643 356 4
09:00:00 750 144 1092 356 4
10:00:00 750 144 1185 356 4
11:00:00 750 144 1580 356 4
12:00:00 750 144 1412 356 4
13:00:00 750 144 1354 356 4
14:00:00 750 144 1157 356 4
15:00:00 750 144 1509 356 4
16:00:00 750 144 1979 356 4
17:00:00 750 144 1803 356 4
18:00:00 750 144 1923 356 4
19:00:00 750 144 2903 356 4
20:00:00 750 144 3556 356 4
21:00:00 750 144 3867 356 4
22:00:00 800 144 2014 72 0
00:00:00 800 0 0 72 0
01:00:00 800 0 0 72 0
02:00:00 800 0 0 72 0