match and group across 2 lines

K

ktlind

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?


Thanks for your help.
 
J

John W. Krahn

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
 
G

Gunnar Hjalmarsson

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+,(.*),(.*)$
 
M

Mirco Wahab

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.
 
K

ktl

$ 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

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

" | \
 
T

Tad McClellan

ktl said:
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.
 
D

Dr.Ruud

(e-mail address removed) 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?


Thanks for your help.

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__
 

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

Staff online

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top