search text in files and grab only selected text

i want to search text in files text.txt..
i only need to grab text start with TEXT and the text below untill 18th lines. the code should grab all 18 lines of text.. is it possible?

TEXT  
  8
1
  6
CONTINUOUS
 62
3
 10
3.8291557E+002
 20
4.0378163E+001
 40
2.0
  1
APPROVED
 41
5.0E-001
  0




### text.txt
LINE
  8
1
  6
CONTINUOUS
 62
6
 10
3.9918501E+002
 20
1.6406581E+001
 11
3.9918501E+002
 21
2.8280413E+002
  0
TEXT
  8
1
  6
CONTINUOUS
 62
3
 10
3.8291557E+002
 20
4.0378163E+001
 40
2.0
  1
APPROVED
 41
5.0E-001
  0
LINE
  8
0
  6
CONTINUOUS
 62
0
 10
-1.0
 20
1.66667E-001
 11
0.0
 21
0.0
  0
ENDBLK
  0
BLOCK
  2
WEDGE
 10
0.0
 20
0.0
 70
0
  0
TEXT
  8
1
  6
CONTINUOUS
 62
3
 10
3.20272E+002
 20
4.660511E+001
 40
3.0
  1
MM
 41
6.0E-001
  0
nazonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sujithkumars123Commented:
I hope your problem will be solved if you are reading the file using BufferedReader.
Read line by line and check whether the string starts with TEXT.
ie
BufferedReader br = new BufferedReader(new FileReader("filename"));
br.readLine().startsWith("TEXT)
0
nazonAuthor Commented:
now i used BufferedReader but i dont know how to only select the 18 lines..

      out.println("nameFile = "+request.getParameter("nameFile"));
      if(request.getParameter("nameFile") != null)      {
      String line;
      BufferedReader input = new BufferedReader (new FileReader (inF));
      //where inF is a file name string
      while ((line = input.readLine()) != null) {
            // the process to reas text start with TEXT n 18 lines below.
      }
      input.close ();
0
nazonAuthor Commented:
found error on

      while ((line = input.readLine().startsWith("TEXT")) != null) {
            out.println("<br>"+line);
      }


C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\WTMIS\org\apache\jsp\PLMS\user\extract_jsp.java:79: incompatible types
found   : boolean
required: java.lang.String
      while ((line = input.readLine().startsWith("TEXT")) != null) {
                                                  ^
1 error
0
sujithkumars123Commented:
out.println("nameFile = "+request.getParameter("nameFile"));
     if(request.getParameter("nameFile") != null)     {
     String line;
     BufferedReader input = new BufferedReader (new FileReader (inF));
     //where inF is a file name string
     while ((line = input.readLine()) != null) {
          // the process to reas text start with TEXT n 18 lines below.
          if (line.startsWith("Text")) {
                 //These are the lines which you need
          }
     }
     input.close ();
0
or3oCommented:
while ((line = input.readLine()) != null) {
      if(line.startsWith("TEXT")){
            int grab=1;
            int grab2=0;                  
      }      
      if( (grab2 >= 0) && (grab2 <= 18) ){
            if(grab==1){      
                  //now u get all 18 lines            
            
            }
            if(grab2==18){
                  grab=0;
            }
      }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.