pattern match with newline

J

justme

hi

i have a file like this

---> STOR ABC.DEF.M.Y1234.MMMMM.TTTTTT
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.
---> QUIT
221 Quit command received. Goodbye.

MMMMM.TTTTTT are dynamic

i want to grab just the lines :
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.

so i did up a code

open(FILE,"test.dat") or die "Cannot open test.dat\n";
while ( <FILE> )
{
print "Got it" if $_ =~ /^125 Storing data set ABC.DEF.M.Y.*\n250
Transfer completed successfully.$/m

}

but it does not work.

can someone correct my mistakes on the regexp. thanks.
 
A

Anno Siegel

justme said:
hi

i have a file like this

---> STOR ABC.DEF.M.Y1234.MMMMM.TTTTTT
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.
---> QUIT
221 Quit command received. Goodbye.

MMMMM.TTTTTT are dynamic

i want to grab just the lines :
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.

so i did up a code

open(FILE,"test.dat") or die "Cannot open test.dat\n";
while ( <FILE> )
{
print "Got it" if $_ =~ /^125 Storing data set ABC.DEF.M.Y.*\n250
Transfer completed successfully.$/m

}

but it does not work.

"Does not work?" You have been around long enough to know that is
insufficient as an error description. It is just rude to expect
your readers to analyze the code to find out what it is you're
complaining about.

When you read a file line-wise, as you do, there cannot be two lines
in a single string. Your pattern assumes that there are. Also,
the dots in the pattern need quoting.

open(FILE,"test.dat") or die "Cannot open test.dat\n";
my $got_one;
while ( <FILE> )
{
$got_one = /^125 Storing data set ABC\.DEF\.M\.Y\./
print "Got it" if $got_one and /^Transfer completed successfully\./;
}

Anno
 
A

Anno Siegel

justme said:
hi

i have a file like this

---> STOR ABC.DEF.M.Y1234.MMMMM.TTTTTT
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.
---> QUIT
221 Quit command received. Goodbye.

MMMMM.TTTTTT are dynamic

i want to grab just the lines :
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.

so i did up a code

open(FILE,"test.dat") or die "Cannot open test.dat\n";
while ( <FILE> )
{
print "Got it" if $_ =~ /^125 Storing data set ABC.DEF.M.Y.*\n250
Transfer completed successfully.$/m

}

but it does not work.

"Does not work?" You have been around long enough to know that is
insufficient as an error description. It is just rude to expect
your readers to analyze the code to find out what it is you're
complaining about.

When you read a file line-wise, as you do, there cannot be two lines
in a single string. Your pattern assumes that there are. Also,
the dots in the pattern need quoting.

open(FILE,"test.dat") or die "Cannot open test.dat\n";
my $got_one;
while ( <FILE> )
{
print "Got it" if $got_one and /^Transfer completed successfully\./;
$got_one = /^125 Storing data set ABC\.DEF\.M\.Y\./
}

Anno
 
A

Anno Siegel

justme said:
hi

i have a file like this

---> STOR ABC.DEF.M.Y1234.MMMMM.TTTTTT
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.
---> QUIT
221 Quit command received. Goodbye.

MMMMM.TTTTTT are dynamic

i want to grab just the lines :
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.

so i did up a code

open(FILE,"test.dat") or die "Cannot open test.dat\n";
while ( <FILE> )
{
print "Got it" if $_ =~ /^125 Storing data set ABC.DEF.M.Y.*\n250
Transfer completed successfully.$/m

}

but it does not work.

"Does not work?" You have been around long enough to know that is
insufficient as an error description. It is just rude to expect
your readers to analyze the code to find out what it is you're
complaining about.

When you read a file line-wise, as you do, there cannot be two lines
in a single string. Your pattern assumes that there are. Also,
the dots in the pattern need quoting.

my $got_one;
while ( <DATA> ) {
print "got it\n" if $got_one and
/^250 Transfer completed successfully\./;
$got_one = /^125 Storing data set ABC\.DEF\.M\.Y\./;
}

Anno
 
C

Charles DeRykus

hi

i have a file like this

---> STOR ABC.DEF.M.Y1234.MMMMM.TTTTTT
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.
---> QUIT
221 Quit command received. Goodbye.

MMMMM.TTTTTT are dynamic

i want to grab just the lines :
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.

so i did up a code

open(FILE,"test.dat") or die "Cannot open test.dat\n";
while ( <FILE> )
{
print "Got it" if $_ =~ /^125 Storing data set ABC.DEF.M.Y.*\n250
Transfer completed successfully.$/m

}

but it does not work.

The read only processes a line at a time so the
regex'll never match both lines.


Something like this will work:

my $qr1 = '^125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT$';
my $qr2 = '^250 Transfer completed successfully.$';

while (<DATA>) {
if (/$qr1/ ) {
{ unless (eof) {
$_ = <DATA>;
if ( /$qr2/ ) {
print "got it ($.)\n";
} else {
/$qr1/ ? redo : next;
}
}
}
}
}
__END__
....
250 Transfer completed successfully.
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,415
Latest member
PeggyCramp

Latest Threads

Top