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

D

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?
 
J

Jan Pluntke

dolphin said:
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
 
J

Jim Cochrane

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 $.
}


--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top