Jump to content
Sign in to follow this  
Steveiwonder

Searching a file and return line number?

Recommended Posts

Steveiwonder

Howdy,

I'm wondering if its possible to search a file for a particular string? and return the line number?

I know it can be done using FileReadLine.. However i have file which are 12,000+ lines long and 15-20 of them.

King Regards,

S


They call me MrRegExpMan

Share this post


Link to post
Share on other sites
Fulano

Well, provided that you let FileReadLine manage the line number on it's own, and send it a file handle instead of a file name, the performance shouldn't be too bad.

Personally though, I tend to outsource those kind of operations to programming languages that are designed for string/file processing by calling them and then catching the return with Run(). That being said, I also tend to end up with AutoIt scripts that are directing their little armies of python/perl/etc scripts - so it's not exactly an elegant solution Posted Image.

Edit: English is being less than kind to me today.

Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites
KaFu

Maybe via _FileReadToArray() and then loop through results to determine the element aka line number? Not sure if that give you a better performance :(...

Share this post


Link to post
Share on other sites
Steveiwonder

Appreciate reply, however the would probbaly take a while too.

I've found an alternative by using Iniread.

Edited by Steveiwonder

They call me MrRegExpMan

Share this post


Link to post
Share on other sites
Fulano

Maybe via _FileReadToArray() and then loop through results to determine the element aka line number? Not sure if that give you a better performance :(...

Mercy, that would use up RAM like there's no tomorrow.

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites
KaFu

Mercy, that would use up RAM like there's no tomorrow.

12.000 lines is like what? ~ 300-400 KB? What amount of RAM can that consume?

Share this post


Link to post
Share on other sites
Fulano

Depends how long the lines are :(.

I just personally think it's a bad habit to write a program that depends on the user never deciding the feed it something massive, especially because I doubt most users would check the size of the file before sending it into a program. It's just not something they think about.

Edit: spelling error.

Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×