in reply to Re: How to escape parens for grep
in thread How to escape parens for grep

Hi graff,

Thanks for the reply. But sometimes the filters does't exists. I mean we may run with out specifying the proto / srchost / dsthost /dir.

So, we need some generic solution to extract this command.

Thanks again.
- Swaroop

Replies are listed 'Best First'.
Re^3: How to escape parens for grep
by davidrw (Prior) on Aug 15, 2005 at 01:52 UTC
    In that case you can split up the regex into multiple regex's and see if each one matches...
    my $s = "tethereal (proto 6 or 17) and src host suntest1 and dst host +suntest2 -w /tmp/dumpfile"; my %info; $info{srchost} = $1 if $s =~ /\bsrc host (\S+)/; $info{dsthost} = $1 if $s =~ /\bdst host (\S+)/; $info{dir} = $1 if $s =~ /\b-w (\S+)/; if( $s =~ /\(proto (.*?)\)/ ){ # this one needs extra processing my $prot = $1; # start with the proto strin +g: "6 or 17" my @prot = $prot =~ /(\d+)/g; # pull out the integers: + (6, 17) $info{protocol = join ',', @prot; # create the desired string: + '6,17' } # if necessary, validate %info here to make sure you can continue...