Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Getting a line from a file Posted by tj29 on 8 Sept 2004 at 6:07 AM
I have a file scan procedure that returns me a list of integer representing the position of all the times it found the word it was searching for. what i want to do is that base on that integer to extract the entire line where the word was found and copy it to another file.
for example
the house is blue.
the car is yellow.
the house is green.

if i search for house it would return 2 integers giving me the position of both "house" what i would like is to extract does two lines and copy them to another file.

any help will be appreciated. thank you
Report
Re: Getting a line from a file Posted by zibadian on 8 Sept 2004 at 7:41 AM
: I have a file scan procedure that returns me a list of integer representing the position of all the times it found the word it was searching for. what i want to do is that base on that integer to extract the entire line where the word was found and copy it to another file.
: for example
: the house is blue.
: the car is yellow.
: the house is green.
:
: if i search for house it would return 2 integers giving me the position of both "house" what i would like is to extract does two lines and copy them to another file.
:
: any help will be appreciated. thank you
:
You can best load the entire file into a stringlist and use it to get the lines. A second stringlist can represent the destination file, and can later be saved onto the disk.
Report
RE: I need it for the following Posted by tj29 on 8 Sept 2004 at 9:30 AM
: : I have a file scan procedure that returns me a list of integer representing the position of all the times it found the word it was searching for. what i want to do is that base on that integer to extract the entire line where the word was found and copy it to another file.
: : for example
: : the house is blue.
: : the car is yellow.
: : the house is green.
: :
: : if i search for house it would return 2 integers giving me the position of both "house" what i would like is to extract does two lines and copy them to another file.
: :
: : any help will be appreciated. thank you
: :
: You can best load the entire file into a stringlist and use it to get the lines. A second stringlist can represent the destination file, and can later be saved onto the disk.
:
thanks.
I try that but the problem is that using stringlist is to slow thats why i was using the scanfile procedure that is really fast but it only returns the positon of every time the it finds a word that you are looking for. the thing is that i need to look in about 100 files (each containing about 1000+ lines) for each line that starts with the word ERROR. for example

ERROR - this is a test

so every line that starts with ERROR i need to put in another file.
i need something fast i was told that scanning was fast and it is the problem is getting the line out of the file.
if you can help i will really appreciated
Report
Re: RE: I need it for the following Posted by zibadian on 8 Sept 2004 at 5:10 PM
: : : I have a file scan procedure that returns me a list of integer representing the position of all the times it found the word it was searching for. what i want to do is that base on that integer to extract the entire line where the word was found and copy it to another file.
: : : for example
: : : the house is blue.
: : : the car is yellow.
: : : the house is green.
: : :
: : : if i search for house it would return 2 integers giving me the position of both "house" what i would like is to extract does two lines and copy them to another file.
: : :
: : : any help will be appreciated. thank you
: : :
: : You can best load the entire file into a stringlist and use it to get the lines. A second stringlist can represent the destination file, and can later be saved onto the disk.
: :
: thanks.
: I try that but the problem is that using stringlist is to slow thats why i was using the scanfile procedure that is really fast but it only returns the positon of every time the it finds a word that you are looking for. the thing is that i need to look in about 100 files (each containing about 1000+ lines) for each line that starts with the word ERROR. for example
:
: ERROR - this is a test
:
: so every line that starts with ERROR i need to put in another file.
: i need something fast i was told that scanning was fast and it is the problem is getting the line out of the file.
: if you can help i will really appreciated
:
The following get procedure is quite slow, but it's easy to program. You open the file as a file of char. Then seek() to the first position of the word error and start to copy it char for char to the other file, until you encounter the #13#10 line ending code. Then you seek() the next position, and start copying. Repeat this seek-copy procedure until all the ERROR-lines are copied.
Another method, which involves 2 scans of each file is making a map of all the ERROR positions and of all the #13#10 positions. Then you can calculate the length of each ERROR line, and use untyped files and BlockRead()/BlockWrite() to perform the copying. It is more error-prone, but could be faster than the previous method.
Report
thanks that worked fine Posted by tj29 on 9 Sept 2004 at 2:31 AM
: : : : I have a file scan procedure that returns me a list of integer representing the position of all the times it found the word it was searching for. what i want to do is that base on that integer to extract the entire line where the word was found and copy it to another file.
: : : : for example
: : : : the house is blue.
: : : : the car is yellow.
: : : : the house is green.
: : : :
: : : : if i search for house it would return 2 integers giving me the position of both "house" what i would like is to extract does two lines and copy them to another file.
: : : :
: : : : any help will be appreciated. thank you
: : : :
: : : You can best load the entire file into a stringlist and use it to get the lines. A second stringlist can represent the destination file, and can later be saved onto the disk.
: : :
: : thanks.
: : I try that but the problem is that using stringlist is to slow thats why i was using the scanfile procedure that is really fast but it only returns the positon of every time the it finds a word that you are looking for. the thing is that i need to look in about 100 files (each containing about 1000+ lines) for each line that starts with the word ERROR. for example
: :
: : ERROR - this is a test
: :
: : so every line that starts with ERROR i need to put in another file.
: : i need something fast i was told that scanning was fast and it is the problem is getting the line out of the file.
: : if you can help i will really appreciated
: :
: The following get procedure is quite slow, but it's easy to program. You open the file as a file of char. Then seek() to the first position of the word error and start to copy it char for char to the other file, until you encounter the #13#10 line ending code. Then you seek() the next position, and start copying. Repeat this seek-copy procedure until all the ERROR-lines are copied.
: Another method, which involves 2 scans of each file is making a map of all the ERROR positions and of all the #13#10 positions. Then you can calculate the length of each ERROR line, and use untyped files and BlockRead()/BlockWrite() to perform the copying. It is more error-prone, but could be faster than the previous method.
:


thanks that worked just fine thanks again



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.