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?


    Thanks for your help.
    , Aug 10, 2007
    #1
    1. Advertising

  2. 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
    #2
    1. Advertising

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

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Aug 10, 2007
    #3
  4. Mirco Wahab Guest

    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
    #4
  5. ktl Guest

    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
    #5
  6. 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.


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad McClellan, Aug 11, 2007
    #6
  7. Dr.Ruud Guest

    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__

    --
    Affijn, Ruud

    "Gewoon is een tijger."
    Dr.Ruud, Aug 11, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nakamura

    splitting a long token across lines

    Nakamura, Apr 4, 2004, in forum: Python
    Replies:
    4
    Views:
    317
  2. Xiao Jianfeng
    Replies:
    23
    Views:
    2,479
    Fredrik Lundh
    Nov 23, 2005
  3. Replies:
    2
    Views:
    318
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
    Oct 19, 2007
  4. H.S.
    Replies:
    9
    Views:
    112
  5. laredotornado
    Replies:
    3
    Views:
    99
Loading...

Share This Page