Sign in to follow this  
Followers 0
Steveiwonder

Searching a file and return line number?

8 posts in this topic

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



#2 ·  Posted (edited)

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

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

#4 ·  Posted (edited)

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

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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  
Followers 0