match and group across 2 lines

Discussion in 'Perl Misc' started by ktlind@gmail.com, Aug 10, 2007.

1. Guest

I would like to group six numbers separated by commas into \$1 thru \$6.
The problem is that four of the numbers are on the first line and two
of the numbers are on the second line. Here is an example of those 2
lines:

SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
,-49.320486,347.560579

The \$ on the end of the first line is a continuation symbol for the
next line.

I can group the first four numbers with:

^SLN\d\d\d = LINE\/(.*),(.*),(.*),(.*) \\$\$

How can I reach down one more line and get the other two numbers?

, Aug 10, 2007

2. John W. KrahnGuest

wrote:
> I would like to group six numbers separated by commas into \$1 thru \$6.
> The problem is that four of the numbers are on the first line and two
> of the numbers are on the second line. Here is an example of those 2
> lines:
>
> SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
> ,-49.320486,347.560579
>
> The \$ on the end of the first line is a continuation symbol for the
> next line.
>
>
> I can group the first four numbers with:
>
> ^SLN\d\d\d = LINE\/(.*),(.*),(.*),(.*) \\$\$
>
> How can I reach down one more line and get the other two numbers?

\$ echo "SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
,-49.320486,347.560579

" | \
perl -lne'
if ( s/\\$\$// ) {
\$_ .= <>;
redo;
}
if ( s/^SLN\d\d\d = LINE\/// ) {
@x = split /\s*,\s*/;
print "@x";
}
'
994.455930 -49.320125 347.561019 994.456333 -49.320486 347.560579

John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

John W. Krahn, Aug 10, 2007

wrote:
> I would like to group six numbers separated by commas into \$1 thru \$6.
> The problem is that four of the numbers are on the first line and two
> of the numbers are on the second line. Here is an example of those 2
> lines:
>
> SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
> ,-49.320486,347.560579
>
> The \$ on the end of the first line is a continuation symbol for the
> next line.
>
>
> I can group the first four numbers with:
>
> ^SLN\d\d\d = LINE\/(.*),(.*),(.*),(.*) \\$\$
>
> How can I reach down one more line and get the other two numbers?

^SLN\d\d\d = LINE\/(.*),(.*),(.*),(.*) \\$\s+,(.*),(.*)\$

--
Email: http://www.gunnar.cc/cgi-bin/contact.pl

4. Mirco WahabGuest

wrote:
> I would like to group six numbers separated by commas into \$1 thru \$6.
> The problem is that four of the numbers are on the first line and two
> of the numbers are on the second line. Here is an example of those 2
> lines:
>
> SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
> ,-49.320486,347.560579
>
> How can I reach down one more line and get the other two numbers?

\$_='
SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
,-49.320486,347.560579
';

my @sixnumbers = /(?<=[,\/])-?[\d\.]+/gs;

Regards

M.

Mirco Wahab, Aug 10, 2007
5. ktlGuest

On Aug 10, 8:22 am, "John W. Krahn" <> wrote:
> wrote:
> > I would like to group six numbers separated by commas into \$1 thru \$6.
> > The problem is that four of the numbers are on the first line and two
> > of the numbers are on the second line. Here is an example of those 2
> > lines:

>
> > SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
> > ,-49.320486,347.560579

>
> > The \$ on the end of the first line is a continuation symbol for the
> > next line.

>
> > I can group the first four numbers with:

>
> > ^SLN\d\d\d = LINE\/(.*),(.*),(.*),(.*) \\$\$

>
> > How can I reach down one more line and get the other two numbers?

>
> \$ echo "SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
> ,-49.320486,347.560579
>
> " | \
> perl -lne'
> if ( s/\\$\$// ) {
> \$_ .= <>;
> redo;
> }
> if ( s/^SLN\d\d\d = LINE\/// ) {
> @x = split /\s*,\s*/;
> print "@x";
> }
> '
> 994.455930 -49.320125 347.561019 994.456333 -49.320486 347.560579
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall

Thanks for the quick response John.
But what is this?

" | \

ktl, Aug 10, 2007

ktl <> wrote:
> On Aug 10, 8:22 am, "John W. Krahn" <> wrote:
>> wrote:
>> > I would like to group six numbers separated by commas into \$1 thru \$6.
>> > The problem is that four of the numbers are on the first line and two
>> > of the numbers are on the second line. Here is an example of those 2
>> > lines:

>>
>> > SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
>> > ,-49.320486,347.560579

>>
>> > The \$ on the end of the first line is a continuation symbol for the
>> > next line.

>>
>> > I can group the first four numbers with:

>>
>> > ^SLN\d\d\d = LINE\/(.*),(.*),(.*),(.*) \\$\$

>>
>> > How can I reach down one more line and get the other two numbers?

>>
>> \$ echo "SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
>> ,-49.320486,347.560579
>>
>> " | \
>> perl -lne'
>> if ( s/\\$\$// ) {
>> \$_ .= <>;
>> redo;
>> }
>> if ( s/^SLN\d\d\d = LINE\/// ) {
>> @x = split /\s*,\s*/;
>> print "@x";
>> }
>> '
>> 994.455930 -49.320125 347.561019 994.456333 -49.320486 347.560579
>>
>> John
>> --
>> Perl isn't a toolbox, but a small machine shop where you
>> can special-order certain sorts of tools at low cost and
>> in short order. -- Larry Wall

>
> Thanks for the quick response John.
> But what is this?
>
> " | \

The ending delimiter for the argument to echo, a pipe, and
a line continuation character.

--
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

7. Dr.RuudGuest

schreef:
> I would like to group six numbers separated by commas into \$1 thru \$6.
> The problem is that four of the numbers are on the first line and two
> of the numbers are on the second line. Here is an example of those 2
> lines:
>
> SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
> ,-49.320486,347.560579
>
> The \$ on the end of the first line is a continuation symbol for the
> next line.
>
>
> I can group the first four numbers with:
>
> ^SLN\d\d\d = LINE\/(.*),(.*),(.*),(.*) \\$\$
>
> How can I reach down one more line and get the other two numbers?
>
>

Why require usage of \$1 to \$6?

#!/usr/bin/perl
use strict;
use warnings;

my \$t = <<'EOT';
SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 \$
,-49.320486,347.560579
EOT

my @numbers = \$t =~ /[\d.-]+/g;

print "\$_\n" for @numbers[ 1 .. \$#numbers ];
__END__

--
Affijn, Ruud

"Gewoon is een tijger."

Dr.Ruud, Aug 11, 2007