Jump to content

Searching a file and return line number?


Recommended Posts

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Link to comment
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!

Link to comment
Share on other sites

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!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...