| prasanth 2006-09-19, 3:56 am |
| hello,
i started learning awk as it is required to trace the data obtained
from ns2 simulations.
the result of a simulation is as follows
tr0.tr--------original file
- 1.997541 0 8 cbr 512 ------- 0 0.0 7.0 487 3409
r 1.997725 8 7 cbr 512 ------- 0 2.0 7.2 495 3408
h 1.99812 1 8 cbr 512 ------- 0 1.0 7.1 490 3410
r 1.998159 8 7 cbr 512 ------- 0 0.0 7.0 487 3409
+ 1.99822 1 8 cbr 512 ------- 0 1.0 7.1 490 3410
In above file each line is having id i.e the last column and i want
only lines start with '-' and 'r'
and then i had to compare the 2nd column of each '-' and 'r' pairs of
same id and print the result if the 2nd column of '-' is greater than
'r'
For the above problem i had done as following
1)I stored the '-' lines in one file named s then stored the 'r' lines
in one file named r
i.e
awk '/^-/ {print $12," ",$2}' tr0.tr > s
awk '/^r/ {print $12," ",$2}' tr0.tr > r
2)then using the two files s and r i had compared the 2nd field of
every id in each file
i.e
BEGIN {
flag = 0;
}
ARGIND == 1 {
split($0,T," ")
x[T[1]] = sprintf("%s",T[2])
next
}
{
if ($2 > x[$1])
flag=1;
}
END {
if(flag==1)
printf("record found such that receiving time < sending time\n")
else
printf("no record found such that receiving time < sending time\n")
}
Now the question is
Is this possible to solve the above without creating the files s and r
and only using tr0.tr file?
|