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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script Stopping

Status
Not open for further replies.

cme4gd6

Technical User
Oct 14, 2003
4
US
Hello there new to this, but glad I like headaches, and found this forum. I was looking for a way to scan a text file and move certain lines to another text file and delete the removed line form the original file. Ok, I found a script to do the first part, but script stops after the first instance and closes instead of continuing. Can someone take a look and figure out what I am doing wrong?
Code:
proc main

string strLine

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

while not feof 0
   fgets 0 strLine              ; get a single line of data
   if strfind strLine "bldn"      ; find beginning of block
      fputs 1 strLine           ; save beginning of block
      while not feof 0          ; loop withing the block
         fgets 1 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
 
Hmm, my response from yesterday disappeared.

Try commenting out the 'exitwhile' line. I think what is happening is that after your endwhile (end of the inner loop) you immeadiatly call the exitwhile, closing out your outer loop, and in effect only one itineration of the outer loop is ran.

Code:
proc main

string strLine

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

while not feof 0
   fgets 0 strLine              ; get a single line of data
   if strfind strLine "bldn"      ; find beginning of block
      fputs 1 strLine           ; save beginning of block
      while not feof 0          ; loop withing the block
         fgets 1 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                ; don't need this exitwhile
   endif
endwhile

fclose 0
fclose 1

endproc
 
If I'm understanding correctly, I think the fgets 1 strLine should actually be fgets 0 strLine. In other words, you are trying to read from the file you are trying to output to in that one line.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top