Steveiwonder Posted March 25, 2010 Share Posted March 25, 2010 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 More sharing options...
Fulano Posted March 25, 2010 Share Posted March 25, 2010 (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 .Edit: English is being less than kind to me today. Edited March 25, 2010 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 More sharing options...
KaFu Posted March 25, 2010 Share Posted March 25, 2010 Maybe via _FileReadToArray() and then loop through results to determine the element aka line number? Not sure if that give you a better performance ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Steveiwonder Posted March 25, 2010 Author Share Posted March 25, 2010 (edited) Appreciate reply, however the would probbaly take a while too. I've found an alternative by using Iniread. Edited March 25, 2010 by Steveiwonder They call me MrRegExpMan Link to comment Share on other sites More sharing options...
Fulano Posted March 25, 2010 Share Posted March 25, 2010 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 More sharing options...
KaFu Posted March 25, 2010 Share Posted March 25, 2010 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? OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Fulano Posted March 25, 2010 Share Posted March 25, 2010 (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 March 29, 2010 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 More sharing options...
junkew Posted March 26, 2010 Share Posted March 26, 2010 1. read the whole file into a string 2. find the position of the value in the string 3. Then do a regexp search for CRLF in the stringleft(wholestring,position) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now