Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Can perl find strings over multiple lines?

Reply
Thread Tools

Can perl find strings over multiple lines?

 
 
osiris@abydos.kmt
Guest
Posts: n/a
 
      11-20-2006
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.
 
Reply With Quote
 
 
 
 
cyborg
Guest
Posts: n/a
 
      11-20-2006
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.


 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      11-20-2006
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

 
Reply With Quote
 
Vronans
Guest
Posts: n/a
 
      11-20-2006
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;



 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      11-20-2006
[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

 
Reply With Quote
 
DJ Stunks
Guest
Posts: n/a
 
      11-20-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
Re: Can perl find strings over multiple lines? Vronans Perl 0 11-20-2006 08:58 PM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
str.find for multiple strings Bart Nessux Python 7 02-12-2004 06:26 PM
passing multiple strings to string.find() hokiegal99 Python 3 08-09-2003 03:55 PM



Advertisments