Thanx everybody for replying.
The problem was not solved
It seems that the second part of the expression
$1~/[0-9]\.(0|5)/ && ...2nd part...
is always true if the first part is true. Whether the expression is "!a[substr($1,1,3)]++" or "!a[$0]".
The solution frostmourn suggested unfortunately didn't compile and I am afraid I don't understand the structure that well in order to make it compile.
Just for the record, the actuall file looks like this (I posted a simplified view before, thought it didn't matter):
"
+ 0.1 0 1 tcp 40 ------- 1 0.0 6.0 0 0
- 0.1 0 1 tcp 40 ------- 1 0.0 6.0 0 0
+ 0.1 7 2 tcp 40 ------- 2 7.0 6.1 0 1
- 0.1 7 2 tcp 40 ------- 2 7.0 6.1 0 1
+ 0.1 8 3 tcp 40 ------- 3 8.0 6.2 0 2
- 0.1 8 3 tcp 40 ------- 3 8.0 6.2 0 2
...
...
- 12.999072 2 7 ack 40 ------- 2 6.1 7.0 59 1228
r 13.002496 2 7 ack 40 ------- 2 6.1 7.0 59 1227
r 13.015712 3 2 ack 40 ------- 2 6.1 7.0 59 1229
+ 13.015712 2 7 ack 40 ------- 2 6.1 7.0 59 1229
- 13.015712 2 7 ack 40 ------- 2 6.1 7.0 59 1229
r 13.019136 2 7 ack 40 ------- 2 6.1 7.0 59 1228
r 13.035776 2 7 ack 40 ------- 2 6.1 7.0 59 1229
"
and the '$1' in my previous example is the '$2' in the actual problem. So this is the code I use based on your suggestions (I also need $1 to be "r", $3 to be 1 and $5 to be "tcp" but it doesn't change anything):
if($1=="r" &&
($2~/\.(0|5)/ && !a[substr($2,1,3)]++) && $3==1 && $5=="tcp")
{
...
}
this didn't work either:
if($1=="r" &&
($2~/\.(0|5)/ && !a[$2]) && $3==1 && $5=="tcp")
{
...
}
still doing something wrong?
//The code I used before and returned all the occurences and not just the first one was:
if($1=="r" &&
($2~ /\.0/ ||$2~ /\.5/) && $3==2 && $5=="tcp")
{
...
}
Thanx in advance.
@rujuta_rahalkar: substr(a,b,c) returns a substring of the string a, that begins at place b (starting from 1) and extends to c places. The effects of the negation and the increment are not clear to me either.