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]