Gossamer Forum
Home : General : Perl Programming :

extract chunks from text file

Quote Reply
extract chunks from text file
I have a text file which looks like this:



"this is the first line 1 note this number one

and the second line, oops there is a number two coming right up 2

and on the third line, of course, there will be a three 3, but not at the end, as that would be too boring

and what to you know, a 2 again

and another 1 on top of that

and lastly a 3, and now the file is over"



Now I want to extract text:

everything between pairs of numbers. Plus, I also want to record the line number of the first occurrence of the number and of the second.

So in the end I should have something like this:

1, stretching from line 1 to line 5: "note this number one and the second line, oops there is a number two coming right up 2 and on the third line, of course, there will be a three 3, but not at the end, as that would be too boring and what to you know, a 2 again and another"

2 (lines 2-4): "and on the third line, of course, there will be a three 3, but not at the end, as that would be too boring and what to you know, a"

3 (lines 3-6): ", but not at the end, as that would be too boring and what do you know, a 2 again and another 1 on top of that and lastly a"

Any suggestions?
kellner