I have a program that looks in a file for lines that start with: ">"
Let's say the file is:
> Hello
Cat
Fish
> Morning
Dog
Lama
Cow
Bat
> Night
Cat
Frog
Hamster

I made a program that looks if the word Morning is in the file. He looks for a sentence that begins with a ">" then he looks to the word behind it. And if there is a match, then he writes that word to an output file.
Now I also want that he takes the word Dog, Lama, Cow and Bat with him. So I want in the output file:

> Morning
Dog
Lama
Cow
Bat

I got him to the point where he writes
> Morning
in the output file. But I also need the lines below that don't start with an ">". I did use this code in my other program:

Java Code:
 
				if (getal == 6) {
					getal = 0;

					if (line.indexOf(">")>=0) {
						// Write the output to a certain file.
						output1b.println(number);
						output1b.flush();
					}
But for that one we needed a certain line part (number), and I was wondering if it would be posible that he looks every line after the matched ">". Besides putting everytime:

Java Code:
 
if (getal == 1) { 
        getal = 0; 
}
And the continue every time with indexOf.
And that for line 1, 2, 3, .... 10 etc.

Is there a way to make this more simple?