PureNewb Posted September 18, 2017 Posted September 18, 2017 Hello,as you can see its my first post and really there is reason for that. The fact: I have a very big file with ~2.050.000 lines and seems like that: Line_1)aaa,1 Line_2)aaa,2 ..... Line_1000)bbb,1 #cs every 1000 lines the first part of starting chars changed #ce Line_1001)bbb,2 Line_1002)bbb,1 ..... Line_2000)ccc,1 The problem is that search with StringinStr line by line is very slow(~8 millisec). i need to search for the first part(aaa/ bbb/ccc) and when i find it,then search from that position for the sec part of search(1,2...999). i was thinking to make a search every 1000lines and when reached my search then continue from that line for sec search but StringinStr doesnt return the line num and any other way its counting the @CRLF to count the lines for return value so its not suits in my case. i hope to be clear.
jchd Posted September 18, 2017 Posted September 18, 2017 Looks like a regexp could do, but without specifics it's hard to advise. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
PureNewb Posted September 18, 2017 Author Posted September 18, 2017 (edited) 38 minutes ago, jchd said: Looks like a regexp could do, but without specifics it's hard to advise. ok lets say that file seems expandcollapse popupSeptember,1 September,2 September,3 September,4 September,5 September,6 September,7 September,8 September,9 September,10 September,11 September,12 September,13 September,14 September,15 September,16 September,17 September,18 September,19 September,20 September,21 September,22 September,23 September,24 September,25 September,26 September,27 September,28 September,29 September,30 October,1 October,2 October,3 October,4 October,5 October,6 October,7 October,8 October,9 October,10 October,11 October,12 October,13 October,14 October,15 October,16 October,17 October,18 October,19 October,20 October,21 October,22 October,23 October,24 October,25 October,26 October,27 October,28 October,29 October,30 November,1 November,2 November,3 November,4 November,5 November,6 November,7 November,8 November,9 November,10 November,11 November,12 November,13 November,14 November,15 November,16 November,17 November,18 November,19 November,20 November,21 November,22 November,23 November,24 November,25 November,26 November,27 November,28 November,29 November,30 how can you search efficient with StringRegExp? Edited September 18, 2017 by Melba23 Added tags
PureNewb Posted September 18, 2017 Author Posted September 18, 2017 lets say that i need to find "October,5",i think that instead of search line by line for "October,5" i could search every 30 line for "October" and after that ,search inside the lines of "October" for ",5".But how can i do that?
jchd Posted September 18, 2017 Posted September 18, 2017 "Search" is a little vague. Do you want to know whether the search string can be found? Or the offset it can be found? Or from there on lookup something else 7 lines after it? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
PureNewb Posted September 19, 2017 Author Posted September 19, 2017 14 hours ago, jchd said: "Search" is a little vague. Do you want to know whether the search string can be found? Or the offset it can be found? Or from there on lookup something else 7 lines after it? Global $SRHC1, $SRHC2, $file, $hFile, $sLine $SRHC1 = "October," $SRHC2 = "5" $file = "C:\Months.txt" $hFile = FileOpen($file) search1() Func search1() ;lookup 30 lines after if not found in first line,but i dont know how to do that yet maybe for $a=0 to 30? While 1 $sLine = FileReadLine($hFile) If @error = -1 Then ExitLoop If StringRegExp($sLine, $SRHC1) Then ;Return the number of $SRHC1 line in order to searh from that line down for $SRHC2 ConsoleWrite( $sLine) Search2() ExitLoop EndIf WEnd EndFunc ;==>search1 Func Search2() While 1 If @error = -1 Then ExitLoop ;Go on the return line number to start find the $SRHC2 If StringRegExp($sLine, $SRHC2) Then ConsoleWrite( $sLine) ExitLoop EndIf WEnd FileClose($hFile) EndFunc ;==>Search2
LarsJ Posted September 19, 2017 Posted September 19, 2017 If there are only 2,000,000 lines, read the entire file into an array with FileReadToArray and search the array (much much faster) instead of the file. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
PureNewb Posted September 19, 2017 Author Posted September 19, 2017 (edited) 2 hours ago, LarsJ said: If there are only 2,000,000 lines, read the entire file into an array with FileReadToArray and search the array (much much faster) instead of the file. thanks for your reply,im trying to do that but it tooks much more time (27.4 sec),is that possible or im doing something wrong? basicaly it write in console 13 times what i need and i need just 1 #include <File.au3> Global $aFile[0], $SRHC1, $SRHC2, $Remark2, $set11, $set12 $SRHC1 = "October," $SRHC2 = "5" _FileReadToArray("C:\Months.txt", $aFile) For $i = 0 To $aFile[0] If StringInStr($aFile[$i], $SRHC1 & $SRHC2) Then $Remark2 = StringSplit($aFile[$i], ",") For $a = 0 To $Remark2[0] $set11 = Round($Remark2[11], 1) $set12 = Round($Remark2[12], 1) ConsoleWrite($set11 & @CRLF) ConsoleWrite($set12 & @CRLF) Next EndIf Next FileClose($aFile) Months.txt Edited September 19, 2017 by PureNewb
LarsJ Posted September 19, 2017 Posted September 19, 2017 I'm talking about FileReadToArray (without an underscore). Not _FileReadToArray (with an underscore). Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
PureNewb Posted September 19, 2017 Author Posted September 19, 2017 (edited) 1 hour ago, LarsJ said: I'm talking about FileReadToArray (without an underscore). Not _FileReadToArray (with an underscore). aha ok,Thanks! Edited September 19, 2017 by PureNewb
kylomas Posted September 19, 2017 Posted September 19, 2017 PureNewb, Based strictly on the detail (or lack thereof) of your request... Local $sSrchArg = 'October,5' Local $sInfile = @ScriptDir & '\months.txt' If StringInStr(FileRead($sInfile), $sSrchArg) Then ConsoleWrite('Search argument found' & @CRLF) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
rudi Posted October 5, 2017 Posted October 5, 2017 Hello, that looks like some log file processing? Maybe you could alter the way the "timestamp" is modified when that file is created to something like 2017-10-01 (instead of October,1) or 20171001 That would make it much easier to dig into the file's content, as you want to do. Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE!
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