Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ok now can this be done by a script?

Status
Not open for further replies.

fsanchez13

Technical User
May 9, 2003
35
US
Below is a small piece of my data. For simplicity I labeled the columns $1 $2 and so on. from 00:00:00 to 22:00:00 $2 will be the same number Then at the next 00:00:00 it will change to a different number till 22:00:00 and so on. How can I get a script to look between 00:00:00 and 22:00:00 and only print out the line with the highest $7 and then move to the next group and do the same all the way down so I only get one printout for each number in $2?

$1 $2 $3 $4 $5 $6 $7
00:00:00 50 0 0 64 0 0
01:00:00 50 0 3 64 0 3
02:00:00 50 0 1 64 0 1
03:00:00 50 0 0 64 0 0
04:00:00 50 0 0 64 0 0
05:00:00 50 0 0 64 0 0
06:00:00 50 0 1 64 0 1
07:00:00 50 0 0 64 0 0
08:00:00 50 0 5 64 0 5
09:00:00 50 0 4 64 0 4
10:00:00 50 0 14 64 0 14
11:00:00 50 0 5 64 0 5
12:00:00 50 0 7 64 0 7
13:00:00 50 0 1 64 0 1
14:00:00 50 0 5 64 0 5
15:00:00 50 0 4 64 0 4
16:00:00 50 0 8 64 0 8
17:00:00 50 0 8 64 0 8
18:00:00 50 0 9 64 0 9
19:00:00 50 0 2 64 0 2
20:00:00 50 0 10 64 0 10
21:00:00 50 0 2 64 0 2
22:00:00 50 0 3 64 0 3
00:00:00 51 0 4 2 0 4
01:00:00 51 0 2 2 0 2
02:00:00 51 0 0 2 0 0
03:00:00 51 0 1 2 0 1
04:00:00 51 0 1 2 0 1
05:00:00 51 0 0 2 0 0
06:00:00 51 0 4 2 0 4
07:00:00 51 0 4 2 0 4
08:00:00 51 0 16 2 0 16
09:00:00 51 0 29 2 0 29
10:00:00 51 0 29 2 0 29
11:00:00 51 0 30 2 0 30
12:00:00 51 0 25 2 0 25
13:00:00 51 0 36 2 0 36
14:00:00 51 0 35 2 0 35
15:00:00 51 0 38 2 0 38
16:00:00 51 0 37 2 0 37
17:00:00 51 0 26 2 0 26
18:00:00 51 0 31 2 0 31
19:00:00 51 0 31 2 0 31
20:00:00 51 0 31 2 0 31
21:00:00 51 0 14 2 0 14
22:00:00 51 0 5 2 0 5
00:00:00 52 0 0 1 0 0
01:00:00 52 0 0 1 0 0
02:00:00 52 0 0 1 0 0
03:00:00 52 0 0 1 0 0
04:00:00 52 0 0 1 0 0
05:00:00 52 0 0 1 0 0
06:00:00 52 0 0 1 0 0
07:00:00 52 0 0 1 0 0
08:00:00 52 0 0 1 0 0
09:00:00 52 0 0 1 0 0
10:00:00 52 0 0 1 0 0
11:00:00 52 0 0 1 0 0
12:00:00 52 0 0 1 0 0
13:00:00 52 0 0 1 0 0
14:00:00 52 0 0 1 0 0
15:00:00 52 0 0 1 0 0
16:00:00 52 0 0 1 0 0
17:00:00 52 0 0 1 0 0
18:00:00 52 0 0 1 0 0
19:00:00 52 0 0 1 0 0
20:00:00 52 0 0 1 0 0
21:00:00 52 0 0 1 0 0
22:00:00 52 0 0 1 0 0
00:00:00 53 0 0 1 0 0
01:00:00 53 0 2 1 0 2
02:00:00 53 0 1 1 0 1
03:00:00 53 0 0 1 0 0
04:00:00 53 0 0 1 0 0
05:00:00 53 0 0 1 0 0
06:00:00 53 0 1 1 0 1
07:00:00 53 0 2 1 0 2
08:00:00 53 0 1 1 0 1
09:00:00 53 0 1 1 0 1
10:00:00 53 0 3 1 0 3
11:00:00 53 0 6 1 0 6
12:00:00 53 0 0 1 0 0
13:00:00 53 0 0 1 0 0
14:00:00 53 0 3 1 0 3
15:00:00 53 0 6 1 0 6
16:00:00 53 0 4 1 0 4
17:00:00 53 0 5 1 0 5
18:00:00 53 0 2 1 0 2
19:00:00 53 0 1 1 0 1
20:00:00 53 0 0 1 0 0
21:00:00 53 0 3 1 0 3
22:00:00 53 0 1 1 0 1
00:00:00 54 0 1 1 0 1
01:00:00 54 0 0 1 0 0
02:00:00 54 0 0 1 0 0
03:00:00 54 0 0 1 0 0
04:00:00 54 0 0 1 0 0
05:00:00 54 0 0 1 0 0
06:00:00 54 0 0 1 0 0
07:00:00 54 0 0 1 0 0
08:00:00 54 0 2 1 0 2
09:00:00 54 0 4 1 0 4
10:00:00 54 0 3 1 0 3
11:00:00 54 0 3 1 0 3
12:00:00 54 0 2 1 0 2
13:00:00 54 0 2 1 0 2
14:00:00 54 0 7 1 0 7
15:00:00 54 0 3 1 0 3
16:00:00 54 0 2 1 0 2
17:00:00 54 0 1 1 0 1
18:00:00 54 0 4 1 0 4
19:00:00 54 0 3 1 0 3
20:00:00 54 0 3 1 0 3
21:00:00 54 0 2 1 0 2
22:00:00 54 0 2 1 0 2
 
#!/usr/bin/perl
open (FILE, thefilename);
$maxval = 0;
while (<FILE>) {
chomp;
@fields = split;
if ($fields[6] > $maxval) {
$maxval = $fields[6];
}
if ($fields[0] eq &quot;22:00:00&quot;) {
print &quot;Max is: $maxval\n&quot;;
$maxval = 0;
}
}
close FILE;
 
#!/usr/bin/ksh

while read -- line
do
set -- $line
[[ $1 = 00:00:00 ]] &&
MaxVal=-1
[[ $7 -gt $MaxVal ]] &&
{
saveline=$line
MaxVal=$7
}
[[ $1 = 22:00:00 ]] &&
print $saveline
done <zfile
 
Highest=0

while read time a b c d e val
do
[ $val -gt $Highest ] && Highest=$val && Line=&quot;$time $a $b $c $d $e $val&quot;
[ &quot;$time&quot; = &quot;22:00:00&quot; ] && echo $Line && Highest=0

done < ./data.txt
 
Apologies.

Didn't read pmurray99's post. Mine is pretty much a repeat of his.

Matt.
 
Awk could be used.

awk 'BEGIN { Highest=0 }
$7 > Highest { Highest=$7;Line=$0 }
/22:00:00/ { print Line; Highest=0 }' data.txt

Matt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top