Re: Regex To get the Job Number and Corresponding state

[email protected] (Asad)
Newsgroups perl.beginners
Message-ID <CAG3LsKHk27MSBtpf7T+H7dbqytcs4VsPaZa5eTiw0N_wtCAtTg@mail.gmail.com>
Thanks a lot.


On Wed, 26 Feb 2025 at 8:55 AM, Jim Gibson <[email protected]> wrote:

> If you are reading a file with normal line endings (e.g., “\n”), then you
> want to parse each line as “key: value” using a regular expression, save
> the job id, current status and current phase values. When you have all
> three, you can check the status and phase values for the values you are
> looking for, print out the job id, and reset all of the variables.
>
> Something like this:
>
> #!/usr/bin/env perl
> use strict;
> use warnings;
>
> my( $status, $phase, $job ) = ('')x3;
>
> for my $line (<DATA>) {
>         chomp($line);
>         print "  $line\n";
>         if ( $line =~ /([^:]+):\s*(.*)/ ) {
>                 my( $key, $val ) = ($1,$2);
>                 if( $key eq 'Job ID' ) {
>                         $job = $val;
>                 }elsif( $key eq 'Current status' ) {
>                         $status = $val;
>                 }elsif( $key eq 'Current Phase' ) {
>                         $phase = $val;
>                 }
>
>                 if( $job && $status && $phase ) {
>                         if( ($status eq 'SUCCEEDED') && ($phase eq
> q("ZDM_SETUP_TGT")) ) {
>                                 print "Job $job is complete\n";
>                         }
>                         ( $status, $phase, $job ) = ('')x3;
>
>                 }
>         }
> }
> __DATA__
> Job ID: 52
> User: zdmuser
> Client: zdmhost
> Job Type: "EVAL"
> Current status: SUCCEEDED
> Current Phase: "ZDM_SETUP_TGT"
> Job ID: 53
> Current status: FAIL
> Current Phase: END
>
>
> > On Feb 25, 2025, at 8:49 AM, Asad <[email protected]> wrote:
> >
> > Hi All,
> >
> > I have a requirement to use regex  , find the Job ID for the Current
> status: SUCCEEDED and Current Phase: "ZDM_SETUP_TGT" from a file
> > which has data in the format gives below :
> >
> > Job ID: 52
> > User: zdmuser
> > Client: zdmhost
> > Job Type: "EVAL"
> > ...
> > Current status: SUCCEEDED
> > Current Phase: "ZDM_SETUP_TGT"
> >
> >
> > Thanks,
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.