plz, i wait your help, AWK problem

I have tracefile of three nodes (0 , 1 and 2 ) as follows:

+ 0.02 0 1 tcp 40 ------- 1 0.0 2.0 0 0
- 0.02 0 1 tcp 40 ------- 1 0.0 2.0 0 0
+ 0.02 2 1 tcp 40 ------- 2 2.1 0.1 0 1
- 0.02 2 1 tcp 40 ------- 2 2.1 0.1 0 1
r 0.025032 0 1 tcp 40 ------- 1 0.0 2.0 0 0
+ 0.025032 1 2 tcp 40 ------- 1 0.0 2.0 0 0
- 0.025032 1 2 tcp 40 ------- 1 0.0 2.0 0 0
r 0.025032 2 1 tcp 40 ------- 2 2.1 0.1 0 1
+ 0.025032 1 0 tcp 40 ------- 2 2.1 0.1 0 1
- 0.025032 1 0 tcp 40 ------- 2 2.1 0.1 0 1
r 0.030064 1 2 tcp 40 ------- 1 0.0 2.0 0 0
+ 0.030064 2 1 ack 40 ------- 1 2.0 0.0 0 2
- 0.030064 2 1 ack 40 ------- 1 2.0 0.0 0 2
r 0.030064 1 0 tcp 40 ------- 2 2.1 0.1 0 1
+ 0.030064 0 1 ack 40 ------- 2 0.1 2.1 0 3
- 0.030064 0 1 ack 40 ------- 2 0.1 2.1 0 3
r 0.035096 2 1 ack 40 ------- 1 2.0 0.0 0 2
+ 0.035096 1 0 ack 40 ------- 1 2.0 0.0 0 2
- 0.035096 1 0 ack 40 ------- 1 2.0 0.0 0 2
...............
...............
.............

I want an awk program which gives me an output file where : each time of node 1, i found total enqueed and total dequeed ( $3=="1") and their difference
like this form :

time ....tot of "+" by node 1....tot of "-"by node 1....(tot of "+" - tot of "-") by node 1

to have a curve : (tot of "+" - tot of "-") by node 1 = f( time )

i try this awk program :

BEGIN { t1=0;t2=0; t3=0;t4=0 }
{

if($1=="+" && $3=="1"&& $5=="tcp")
{if($1=="-")
{
t3+=$6;
}

t1=$2;
t2+=$6;
t4=t2-t3;
{print "\t\n"t1,t2,t3,t4}
}
} 
END {""}

but without goud result

plz, i wait your help

Could you post an example output given the above input?

[asaadaoui@elec ~]$ awk -f 3var2.awk salem.tr> 3var2.txt
[asaadaoui@elec ~]$ gedit 3var2.txt

i have this output file : 3var2.txt




0.025032 40 0 40
	
0.025032 80 0 80
	
0.04596 1120 0 1120
	
0.04596 2160 0 2160
	
0.046792 3200 0 3200
	
0.046792 4240 0 4240
	
0.067688 5280 0 5280
	
0.067688 6320 0 6320
	
0.06852 7360 0 7360
	
0.06852 8400 0 8400
	
0.069352 9440 0 9440
	
0.069352 10480 0 10480
	
0.070184 11520 0 11520
	
0.070184 12560 0 12560
	
0.089416 13600 0 13600
	
0.089416 14640 0 14640
	
0.090248 15680 0 15680
	
0.090248 16720 0 16720
	
0.09108 17760 0 17760
	
0.09108 18800 0 18800
	
0.091912 19840 0 19840
	
0.091912 20880 0 20880
	
0.092744 21920 0 21920
	
0.092744 22960 0 22960
	
0.093576 24000 0 24000
	
0.093576 25040 0 25040
	
0.094408 26080 0 26080
................
...............
................

you see that tot "-" always equal to zero

thanks to your quick reply

I suppose I was not clear,
I meant, could you post an example of the correct (desired) output?

I suppose for example, he correct (desired) output like the following result:

0.025032    40         0       40
	
0.025032    80         40      40
	
0.04596     1120      140      980
	
0.04596      2160    1140     1020
	
0.046792     2000    1140     860
	
...............................
...............................
..............................

first is the time....second is the tot of "+" by node 1....third is the tot of "-"by node 1....forth is the difference (tot of "+" - tot of "-") by node 1

the goal of this work is to have a curve : (total of "+" - total of "-") by node 1 = f( time )

thanks for the help

If I understand correctly:

awk '$5 == "tcp" {
  $1 == "+" && node_plus[$3] += $6
  $1 == "-" && node_minus[$3] += $6
  print $2, node_plus[$3], node_minus[$3], \
    node_plus[$3] - node_minus[$3]
    }' infile

---------- Post updated at 12:01 AM ---------- Previous update was at 12:00 AM ----------

Do you want only node 1? The code above gives the rolling sum for all nodes (per node).

yes i want only for node 1

So the array is unecessary:

awk '$3 == 1 && $5 == "tcp" {
  $1 == "+" && node_plus += $6
  $1 == "-" && node_minus += $6
  print $2, node_plus, node_minus, \
    node_plus - node_minus
    }' OFS='\t' infile

is this correct if i want only for node 1

($5 == "tcp" && $3=="1") {
  $1 == "+" && node_plus[$3] += $6
  $1 == "-" && node_minus[$3] += $6
  print $2, node_plus[$3], node_minus[$3], \
    node_plus[$3] - node_minus[$3]
    }

Yes, but the arrays are redundant, see my previous post.

i try your awk program and l reply the result
please how exactly write the program, like this script or other:

BEGIN{}

awk'$3 == 1 && $5 == "tcp" {
  $1 == "+" && node_plus += $6
  $1 == "-" && node_minus += $6
  print $2, node_plus, node_minus, \
    node_plus - node_minus
    }' OFS='\t' infile
END{""}

i try your awk program and l reply the result
please how exactly write the program, like this script or other:

BEGIN{}

awk'$3 == 1 && $5 == "tcp" {
  $1 == "+" && node_plus += $6
  $1 == "-" && node_minus += $6
  print $2, node_plus, node_minus, \
    node_plus - node_minus
    }' OFS='\t' infile
END{""}

---------- Post updated at 05:28 PM ---------- Previous update was at 05:19 PM ----------

[/COLOR]plz
i have the following result :

[asaadaoui@elec ~]$ awk -f try.awk salem.tr> try.txt
awk: try.awk:4: awk '$3 == 1 && $5 == "tcp"{
awk: try.awk:4:     ^ invalid char ''' in expression

plz, how exactly i write the program

---------- Post updated at 06:11 PM ---------- Previous update was at 05:28 PM ----------

Hi Radoulov,
Congratulation
The program is correct

i wrote the following program :

BEGIN { node_plus=0;node_minus=0; }
{

$3 == 1 && $5 == "tcp"
{
  $1 == "+" && node_plus += $6
  $1 == "-" && node_minus += $6
  print $2, node_plus, node_minus, \
    node_plus - node_minus
}
} 
END {""}

and I have the following part of result ( tracefile ):

0.02 40 0 40
0.02 40 40 0
0.02 80 40 40
0.02 80 80 0
0.025032 80 80 0
0.025032 120 80 40
0.025032 120 120 0
0.025032 120 120 0
0.025032 160 120 40
0.025032 160 160 0
0.030064 160 160 0
0.030064 200 160 40
0.030064 200 200 0
0.030064 200 200 0
0.030064 240 200 40
0.030064 240 240 0
0.035096 240 240 0
................
.................
................

thank you very much, Sir RADOULOV.