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

searching a file from the bottom of a file up

Status
Not open for further replies.

Matta25

Technical User
Jan 6, 2004
82
0
0
US
Is there a way to Fseek to the end of file and then move up 13 lines and read in that line.
Thanks
 
Or can i search for a string and then read in the next line after that string. (The string will be on a different line all the time.)
Thanks
 
I just put this script together that will search the file for a string then write that line plus the next 8 lines to a file. (These 9 line have totals on them.) Is there a way to continue searching the file for the same string and if it finds the string again, write the line to another file. (This file will sometimes have this string twice.)

(Once these file are written the data will always be in the same place and I can pull the data.)
Thanks again


While findfirst "c:\test\test.DAT"
fopen 0 $filespec READ TEXT
while not feof 0
fgets 0 Code
termmsg "%s `r`n" code
if strfind Code "TOTALS FOR THIS FILE"
fopen 1 "C:\test\New File with string.txt" CREATE TEXT
fputs 1 code
fgets 0 Code
fputs 1 code
fgets 0 Code
fputs 1 code
fgets 0 Code
fputs 1 code
fgets 0 Code
fputs 1 code
fgets 0 Code
fputs 1 code
fgets 0 Code
fputs 1 code
fgets 0 Code
fputs 1 code
fgets 0 Code
fputs 1 code
fclose 1
Else
Goto end
EndIf
EndWhile
fclose 0
EndWhile
end:
PWexit
EndProc
 
Are you looking just to match the first string you are looking for? If so, save that to another string and then you can use the strfind command to search for that string in each line you read from then on.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top