Help with filtering trace file through grep

Hi,
I am using NS2 and i need to filter a trace file (part of which is shown below):

  • 33.91576 2 3 tcp 1040 ------- 1 0.0 4.0 1115 2258
    r 33.918907 4 3 ack 40 ------- 1 4.0 0.0 1107 2272
    + 33.918907 3 2 ack 40 ------- 1 4.0 0.0 1107 2272
  • 33.918907 3 2 ack 40 ------- 1 4.0 0.0 1107 2272
    r 33.9192 2 0 ack 40 ------- 1 4.0 0.0 1103 2264
    + 33.9192 0 2 tcp 1040 ------- 1 0.0 4.0 1123 2275
  • 33.9192 0 2 tcp 1040 ------- 1 0.0 4.0 1123 2275
    r 33.93256 2 3 tcp 1040 ------- 1 0.0 4.0 1111 2250
    + 33.93256 3 4 tcp 1040 ------- 1 0.0 4.0 1111 2250
  • 33.93256 3 4 tcp 1040 ------- 1 0.0 4.0 1111 225
    ........................

The file needs to be filtered such that column number 3 should only contain "3" and column number 1 should only contain "r" using GREP (or awk).

Any help is greatly appreciated!

awk '$1=="r" && $3==3' file
1 Like

Not really correct, but simple.

grep "^r.* 3 " file
1 Like
$ ruby -ane 'print if $F[0]+$F[2]=="r3"' file
1 Like

@ everyone...thanks a bunch to all of you for replying so fast!

bartus11`s code worked perfectly so i didnt try the rest but i`m pretty sure they all work fine!! thank again!!

exactly:

grep "^r [^ ]* 3 "