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

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

am 28.09.2007 10:19:39 von Dolphin

Hi Eveyone
I have a question now,How to get some specify lines in a block of a
file?
For example , I have a big file just like below
.................
..............
...........
...........
..........
ABC
{
..................
................
.................
................
...............
}
...............
..................
I just want to get some specify lines in the block of ABC{ }.
What should I do?

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

am 28.09.2007 15:09:44 von Jan Pluntke

dolphin writes:

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

[...]

> 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

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

am 28.09.2007 21:55:17 von Jim Cochrane

On 2007-09-28, Jan Pluntke wrote:
> dolphin 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 $.
}


--