Re: How to get some specify lines in a block of a file?



On 2007-09-28, Jan Pluntke <ulmai@xxxxxx> wrote:
dolphin <jdxyw2004@xxxxxxxxx> writes:

I have a question now,How to get some specify lines in a block of a
file?

Sorry, your English is pretty good, but I can't but help correct this:

specify -> specific


[...]

I just want to get some specify lines in the block of ABC{ }.
What should I do?

If I understand your question correctly,

perldoc -q lines between patterns

might provide an answer.

Regards,
Jan

To make my post relevant - dolphin pointed to the answer, or info that
can lead to your answer, which is - from the perldoc faq:

Found in /usr/lib/perl5/5.8.6/pod/perlfaq6.pod
How can I pull out lines between two patterns that are themselves on
different lines?

You can use Perlâ??s somewhat exotic ".." operator (documented in per-
lop):

perl -ne â??print if /START/ .. /END/â?? file1 file2 ...

If you wanted text and not lines, you would use

perl -0777 -ne â??print "$1\n" while /START(.*?)END/gsâ?? file1 file2 ...

But if you want nested occurrences of "START" through "END", youâ??ll run
up against the problem described in the question in this section on
matching balanced text.

Hereâ??s another example of using "..":

while (<>) {
$in_header = 1 .. /^$/;
$in_body = /^$/ .. eof();
# now choose between them
} continue {
reset if eof(); # fix $.
}


--

.