HI Rob,
>From the output generated below, I would like to obtain the string from
"RPC: Timed out" onwards. This string corresponds to the response attribute.
Another example of the response attribute is the "program 100008 version 1
sleeping". 
107374 / 1 / udp / 64018 / rpcinfo / RPC: Timed out
100008 / 1 / tcp / 55684 / sprayd / program 100008 version 1 sleeping

Hence I would like to know if there is a more efficient way of performing a
pattern match which also includes delimiters like the ":" and spaces? Since
you pointed out that "There's nothing to differentiate taking the last word
of 'program 100008 version 1 sleeping' to say 'sleeping', as opposed to the
last two words of 'RPC: Timed out' to say 'Timed out'.", I would just like
to obtain the service names rpcinfo and sprayd and the response attribute
i.e. "RPC: Timed out" (ignoring the ":" before RPC i.e. ":RPC") and
"program 100008 version 1 sleeping". 

Could anyone kindly help me out?

Thanks.



-----Original Message-----
From: Rob Dixon [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 11, 2003 12:04 AM
To: [EMAIL PROTECTED]
Subject: Re: pattern matching 


Chern Jian Leaw wrote:
> HI,
>
> I have a text file below which is simply an output from the UNIX utility
> rpcinfo:
>
> 100008    1   udp  55734   walld         program 100008 version 1 ready
and
> waiting
> 107374    1   udp  64018   rpcinfo: RPC: Timed out
> 100008    1   tcp  55684   sprayd       program 100008 version 1 sleeping
>
> In the attached script, I'm extracting the lines from the file which does
> NOT match the string "ready and waiting". For those lines from the rpcinfo
> output which did not match "ready and waiting" string, an e-mail would be
> sent out to some respective sys admin.
>
> In the script, I've obtained the attributes i.e. the program no, version,
> protocol, port, and response via pattern matching:
> $waiting[$lines]=~m/^(\d+)\s+(\d+)\s+(\w+)\s+(\d+)\s+(.*)$/;
> where $waiting[lines] contains all lines not matching the string "ready
and
> waiting".
>
> However, for the case of the response having the pattern:
> rpcinfo:RPC:Timed Out
> I would have to split this pattern with the ":" as the delimiter in order
to
> obtain the output format as below, in the e-mail content:
>
> PROG NO VERSION PROTOCOL PORT SERVICE RESPONSE
> 107374        1    udp 64018
> rpcinfo Timed Out
> 100008        1    udp 55684
> sprayd sleeping
>
> I was wondering if there are ways which I can do so in just a single
pattern
> matching arithmetic to obtain the attributes to correspond with the output
> format above?
>
> Any other better/more efficient ideas on performing such pattern match
would
> indeed be appreciated.

Well I can offer you the code below, which splits each line on one or
more whitespace characters, optionally preceded by a space. But I can't
see a way of describing how much of the end of the text you want as
the 'response'. There's nothing to differentiate taking the last word
of 'program 100008 version 1 sleeping' to say 'sleeping', as opposed to
the last two words of 'RPC: Timed out' to say 'Timed out'. Can you specify
what you need a little more precisely, and show us a better example of the
input?

Cheers,

Rob



  while (<DATA>) {
    chomp;
    next if /ready and waiting/;
    my @details = split /:?\s+/, $_, 7;
    shift @details;
    $" = ' / ';
    print "@details\n";
  }


  __DATA__
  100008    1   udp  55734   walld         program 100008 version 1 ready
and waiting
  107374    1   udp  64018   rpcinfo: RPC: Timed out
  100008    1   tcp  55684   sprayd       program 100008 version 1 sleeping

OUTPUT

  107374 / 1 / udp / 64018 / rpcinfo / RPC: Timed out
  100008 / 1 / tcp / 55684 / sprayd / program 100008 version 1 sleeping




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to