I have the below code which calculates the time difference between src and dst from a large trace file. The code works for a given source and destination. However, I want to automate the code to go over any src and destination. The format of the source is like that: X.Y where x is always =2 and Y is varying (i.e. 0,1,2,3,4,..). The format of destination: Z.T where Z and T varying (could be 3.5, 5.7, 5.100, .....).
BEGIN {
src="2.2431"; dst="5.20";
num_samples = 0;
total_delay = 0;
}
/^\+/&&$9==src&&$10==dst {
t_arr[$12] = $2;
};
/^r/&&$9==src&&$10==dst{
if (t_arr[$12] > 0) {
num_samples++;
delay = $2 - t_arr[$12];
total_delay += delay;
};
};
END{
avg_delay = total_delay/num_samples;
print "Average end-to-end transmission delay is " avg_delay " seconds";
print "Measurement details:";
print " - Since packets are created from the address " src;
print " - Until the packets are destroyed at the address " dst;
};
My PROBLEM is how to automate the code and make the condition something like:
/^\+/&&$9==(2.anyNumber)&&$10==(AnyNumber.AnyNumber)
sample of the input file :
+ 0.163944 2 1 a 40 ------- 1 2.4 5.4 0 10
+ 0.215400 2 1 a 40 ------- 1 2.4 5.4 1 28
+ 0.239528 2 1 t 40 ------- 1 2.4 5.4 0 37
+ 0.287784 2 1 t 1040 ------- 1 2.4 5.4 1 62
+ 0.287784 2 1 t 1040 ------- 1 2.4 5.4 2 63
- 0.147407 1 0 a 40 ------- 1 2.1 5.1 0 6
r 0.148256 0 5 a 40 ------- 1 2.0 5.0 0 2
+ 0.148256 5 0 t 1040 ------- 1 5.0 2.0 1 7
+ 0.166969 5 0 t 40 ------- 1 5.5 2.5 0 11
- 0.166969 5 0 t 40 ------- 1 5.5 2.5 0 11
r 0.188072 0 5 a 40 ------- 1 2.4 5.4 0 10
r 0.239528 0 5 a 40 ------- 1 2.4 5.4 1 28
r 0.263656 0 5 t 40 ------- 1 2.4 5.4 0 37
r 0.317128 0 5 t 1040 ------- 1 2.4 5.4 1 62
r 0.318792 0 5 t 1040 ------- 1 2.4 5.4 2 63
Any suggestions!!!
$9 : is the src value (X.Y)
$10: is the dst value(Z.T)
$2 : the time .
$12 is the ID of the packet which unique from src to destination. Since there are middle nodes between src-->destination, the ID might be seen repeated, that's why I taking the average.
the expected output:
average time from src: 2.Y -->Z.T : value seconds