Can perl find strings over multiple lines?

Discussion in 'Perl Misc' started by osiris@abydos.kmt, Nov 20, 2006.

  1. Guest

    Is it possible to search for strings in a file over multiple lines
    using a one-liner from the shell?

    What I want to do is find all the text between
    a line beginning with "--" or "-- " and
    ending with ")$" where '$' is, of course, the EOL char.

    I also would like to know how to find the exclusion
    so that the output produces everything but the enclosed string above.
    Is this possible with perl? Thanks a million.

    I have perl 5.8.6 on OSX 10.4 and 5.6.1 on Solaris 7.
     
    , Nov 20, 2006
    #1
    1. Advertising

  2. cyborg Guest

    Give us some examples instead of just descriptions.
    Some sample text, maybe, or the original plus the result you want to
    achieve.

    wrote:
    > Is it possible to search for strings in a file over multiple lines
    > using a one-liner from the shell?
    >
    > What I want to do is find all the text between
    > a line beginning with "--" or "-- " and
    > ending with ")$" where '$' is, of course, the EOL char.
    >
    > I also would like to know how to find the exclusion
    > so that the output produces everything but the enclosed string above.
    > Is this possible with perl? Thanks a million.
    >
    > I have perl 5.8.6 on OSX 10.4 and 5.6.1 on Solaris 7.
     
    cyborg, Nov 20, 2006
    #2
    1. Advertising

  3. Paul Lalli Guest

    wrote:
    > Is it possible to search for strings in a file over multiple lines
    > using a one-liner from the shell?


    Yes, it is.

    > What I want to do is find all the text between
    > a line beginning with "--" or "-- " and
    > ending with ")$" where '$' is, of course, the EOL char.
    >
    > I also would like to know how to find the exclusion
    > so that the output produces everything but the enclosed string above.
    > Is this possible with perl?


    Yes, it is.

    If you would like assistance with the demonstration of such abilities,
    please read and follow the Posting Guidelines for the group. Most
    specifically, please post your best attempt to solve the problem you're
    having, along with a description of how your attempt is not working
    sufficiently. Be sure to include example input, desired output, and
    actual output.

    > Thanks a million.


    You're welcome.

    Paul Lalli
     
    Paul Lalli, Nov 20, 2006
    #3
  4. Vronans Guest

    Paul Lalli wrote:
    > wrote:
    >> Is it possible to search for strings in a file over multiple lines
    >> using a one-liner from the shell?

    >
    > Yes, it is.
    >
    >> What I want to do is find all the text between
    >> a line beginning with "--" or "-- " and
    >> ending with ")$" where '$' is, of course, the EOL char.
    >>
    >> I also would like to know how to find the exclusion
    >> so that the output produces everything but the enclosed string above.
    >> Is this possible with perl?

    >
    > Yes, it is.
    >
    > If you would like assistance with the demonstration of such abilities,
    > please read and follow the Posting Guidelines for the group. Most
    > specifically, please post your best attempt to solve the problem
    > you're having, along with a description of how your attempt is not
    > working sufficiently. Be sure to include example input, desired
    > output, and actual output.


    While it's always good for one to attempt to solve their own problem, I
    don't see why the assumption is often made that they did not do so.
    Further more, why are some people so concerned with that in the first
    place? Especially for a potentially simple answer in this case.

    He gave a description of what he was trying to do. You could of included
    an answer similar like mine )below) instead of just general guidelines
    and leave it at that. Do not get me wrong, your guidelines are good for
    general purposes, but by themselves do not really offer anything to the
    topic it self.



    It sounds to me like he could find the 's' modifier for a regex match,
    which cause the '.' meta char to match embedded new lines.

    This should to do what the OP wants (un tested):

    @matches = $full_text =~ m!--(.*?)\)\$!sg;
     
    Vronans, Nov 20, 2006
    #4
  5. Paul Lalli Guest

    [removed non-existent group 'comp.lang.perl']

    Vronans wrote:
    > Paul Lalli wrote:
    > > wrote:
    > >> Is it possible to search for strings in a file over multiple lines
    > >> using a one-liner from the shell?

    > >
    > > Yes, it is.
    > >
    > >> What I want to do is find all the text between
    > >> a line beginning with "--" or "-- " and
    > >> ending with ")$" where '$' is, of course, the EOL char.
    > >>
    > >> I also would like to know how to find the exclusion
    > >> so that the output produces everything but the enclosed string above.
    > >> Is this possible with perl?

    > >
    > > Yes, it is.
    > >
    > > If you would like assistance with the demonstration of such abilities,
    > > please read and follow the Posting Guidelines for the group. Most
    > > specifically, please post your best attempt to solve the problem
    > > you're having, along with a description of how your attempt is not
    > > working sufficiently. Be sure to include example input, desired
    > > output, and actual output.

    >
    > While it's always good for one to attempt to solve their own problem, I
    > don't see why the assumption is often made that they did not do so.


    Because absolutely no indication of any kind was given that the OP made
    any attempt.

    > Further more, why are some people so concerned with that in the first
    > place?


    Because this newsgroup is not a free tech-support system. Everyone who
    answers a post here is a volunteer. There are only so many posts that
    any one person can volunteer to answer in a given day. Most people
    here, myself included, are for more inclined to offer assistance to
    people who've demonstrated an attempt to solve the problem first.
    Therefore, someone who makes no such demonstration is far less likely
    to have their problem answered.

    My comments were intended to help the OP help himself. By making an
    attempt and following the Guidelines of the group, the OP has the best
    chance to actually get his problem solved.

    If you want to go ahead and solve people's problems regardless of the
    content of their questions, by all means, please continue to do so. No
    one will stop you, and I for one will applaud you. ... Right up to the
    moment where you say "enough is enough" and decide you can't devote any
    more time to doing so.

    > Do not get me wrong, your guidelines are good for
    > general purposes, but by themselves do not really offer anything to the
    > topic it self.


    Nor are they supposed to. I am of the "Teach a Man to Fish"
    philosophy. Your response helps the OP with this one particular post.
    Will you necessarily be here to also answer his next one? And the one
    after that? My response teaches him how to ask a better question so
    that next time, far more people will be likely to respond to him, in
    case you're not around.

    Paul Lalli
     
    Paul Lalli, Nov 20, 2006
    #5
  6. DJ Stunks Guest

    Vronans wrote:
    > Paul Lalli wrote:
    > > wrote:
    > >> Is it possible to search for strings in a file over multiple lines
    > >> using a one-liner from the shell?

    > >
    > > Yes, it is.
    > > <snip>
    > > post your best attempt to solve the problem
    > > you're having, along with a description of how your attempt is not
    > > working sufficiently. Be sure to include example input, desired
    > > output, and actual output.

    >
    > While it's always good for one to attempt to solve their own problem, I
    > don't see why the assumption is often made that they did not do so.
    > Further more, why are some people so concerned with that in the first
    > place? Especially for a potentially simple answer in this case.
    >
    > He gave a description of what he was trying to do. You could of included
    > an answer similar like mine )below) instead of just general guidelines
    > and leave it at that. Do not get me wrong, your guidelines are good for
    > general purposes, but by themselves do not really offer anything to the
    > topic it self.
    >
    > It sounds to me like he could find the 's' modifier for a regex match,
    > which cause the '.' meta char to match embedded new lines.
    >
    > This should to do what the OP wants (un tested):
    >
    > @matches = $full_text =~ m!--(.*?)\)\$!sg;


    Aside from the points Paul made in rebuttal with which I agree
    strongly, I think it's worth mentioning that your solution is by your
    admission untested, and "should" do what the OP wants provided you've
    interpreted his description correctly.

    Anything I post I test, something made impossible by not having sample
    input and desired output.

    Secondly, we have, many times in the past, provided solutions to
    posters only to find out later on that their description was poor, and
    frequently misses edge cases. I would rather give a definitive answer
    once than multiple guesses at potential solutions.

    Finally, the posting guidelines are to help the posters, not the
    responders. Programming is, and must always be, an exact science. If
    an individual cannot express their issue exactly and specifically I
    don't think they're going to have much luck in their programming
    career. Getting them to formulate such a question should help them
    think logically and rationally, but if not, I'm sure "ballet reviewer"
    is still available as a career choice.

    -jp
     
    DJ Stunks, Nov 20, 2006
    #6
    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. Rigga

    Text over multiple lines

    Rigga, Jun 20, 2004, in forum: Python
    Replies:
    10
    Views:
    712
    Rigga
    Jun 21, 2004
  2. Vronans
    Replies:
    0
    Views:
    6,319
    Vronans
    Nov 20, 2006
  3. Sara
    Replies:
    6
    Views:
    285
    John W. Krahn
    Apr 12, 2004
  4. Markus Dehmann
    Replies:
    1
    Views:
    150
    Tad McClellan
    Sep 26, 2006
  5. Cah Sableng
    Replies:
    0
    Views:
    263
    Cah Sableng
    Apr 23, 2007
Loading...

Share This Page