Can your search term occur more than once in the file? If so, what do you want to happen when a second instance is fewer than ten lines after the first? Is it possible that a "Findme" occurs on the last line of the file and if so, what do you want to happen then? For example:
This is line1 At line 2. Did you Findme This is line3 This is line4 this is another Findme embedded in line 5 This is line 6 this is line 7 this is line 8 Line 9: yet another findme line 10 line 11 line 12 line 13 line 14 line 15 line 16 line 17 line 18 line 19 is the 10th line after the next-to-last instance of searchterm line 20 line 21 and so on... line 23 24: last Findme
IMO, you'll need no more than beginner skills to write a script (solution OR attempt-at-a-solution STILL left to the OP) that produces this output:
At line 2. Did you Findme This is line3 This is line4 this is another Findme embedded in line 5 This is line 6 this is line 7 this is line 8 Line 9: yet another findme line 10 line 11 line 12 line 13 line 14 line 15 line 16 line 17 line 18 line 19 is the 10th line after the next-to-last instance of searchterm 24: last Findme done
...but whether or not this is comensurate with your "requirement" (job? homework? other?) depends on the answers to the questions posed above.
In reply to Re: Searching for a string in a text and printing the next few lines
by ww
in thread Searching for a string in a text and printing the next few lines
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |