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 <asad.hasan2...@gmail.com> 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, -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/