Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting a random number of lines from file

Status
Not open for further replies.

rcavour

Technical User
Sep 21, 2006
9
US
I am wondering if my script is doing too much work, and would like to know if there is a cleaner way of doing this.

I am saving the scrollback buffer to a file, and later I try to extract a block of information from this file. (I have no way of knowing the block size, which can range from 2 to 50 lines, from response to response). All I know is the string in the beginning of the block and at the end. Here is a sample:
Code:
proc main

string strLine

fopen 0 "c:\temp.txt" READ       ; File with original data
fopen 1 "c:\newtemp.txt" CREATE  ; File with extracted data

while not feof 0
   fgets 0 strLine              ; get a single line of data
   if strfind strLine "XX"      ; find beginning of block
      fputs 1 strLine           ; save beginning of block
      while not feof 0          ; loop withing the block
         fgets 0 strLine        ; continue getting data
         if strfind strLine "&" ; look for end of block
           fputs 1 strLine      ; save end of block
           exitwhile            ; done extracting block
         else
           fputs 1 strLine      ; keep writing block
         endif
       endwhile
       exitwhile                ; done with file
   endif
endwhile

fclose 0
fclose 1

endproc

Thank you.
 
That looks pretty good to me. The only way I can think to cut that down, and it may not even work, would be to clear the scrollback buffer using the termreset command, use waitfor to detect the end of the data block, and then save the scrollback buffer. This might not result in any less "fluff" in your text file and your script may still be required to parse through the file to make sure only what you want is present.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top