blizzedout Posted February 6, 2007 Share Posted February 6, 2007 What would be the best way to match a string in a large file? And is there a size limit of the file your searching in? Link to comment Share on other sites More sharing options...
/dev/null Posted February 6, 2007 Share Posted February 6, 2007 What would be the best way to match a string in a large file? And is there a size limit of the file your searching in?what do you mean by "match a string"? If you just want to know if a file contains a certain string, you can use the DOS command find. Usage: find "text" c:\largefile.txt . Should work fine with "large" files. __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
MrCreatoR Posted February 6, 2007 Share Posted February 6, 2007 (edited) What would be the best way to match a string in a large file?By match a string you mean like search a string in file? From the help file: 15. What are the current technical limits of AutoIt v3? Maximum string length: 2,147,483,647 characters Therefore, if you read the file into a string, and the file contain more then 2,147,483,647 characters, you will run into problem. But, you don't have to read all file at once , you can do this by line each time: $String = "test" $File = @ScriptDir & "\test.txt" $FindArr = _FindStrInFile($File, $String) If IsArray($FindArr) And $FindArr[0] <> "" Then MsgBox(64, "Results", "The string <" & $String & "> was found in line # " & $FindArr[1] & @CR & "(" & $FindArr[0] & ")") ElseIf $FindArr <> -1 Then MsgBox(48, "Results", "The string <" & $String & "> was not found in file <" & $File) ElseIf $FindArr = -1 Then MsgBox(48, "Results", "The file <" & $File & "> was not found") EndIf Func _FindStrInFile($File, $String) If Not FileExists($File) Then Return -1 Local $fOpen = FileOpen($File, 0), $LineCount = 0 Dim $ret[2] While 1 $LineCount += 1 $CurrentLine = FileReadLine($fOpen) If @error = -1 Then ExitLoop If StringInStr($CurrentLine, $String) Then $ret[0] = $CurrentLine $ret[1] = $LineCount EndIf WEnd Return $ret EndFunc Edited February 6, 2007 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 6, 2007 Moderators Share Posted February 6, 2007 What's wrong with StringInStr()? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
blizzedout Posted February 6, 2007 Author Share Posted February 6, 2007 (edited) What's wrong with StringInStr()?well im running that function on a 120KB file and it takes like a whole second... and is there a better way to test more than one match than to just repeat it 100 times (any faster method?)ahh i read the function and the issue was that the file i had used 11,000 lines. if its 1 line its 1 string. Edited February 6, 2007 by blizzedout Link to comment Share on other sites More sharing options...
blizzedout Posted February 6, 2007 Author Share Posted February 6, 2007 i was able to get it to work in cmd prompt but cant seem to get autoit to use it and determine results. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 6, 2007 Moderators Share Posted February 6, 2007 StringRegExp() Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
blizzedout Posted February 8, 2007 Author Share Posted February 8, 2007 StringRegExp()when i run the cmd find "text" c:\largefile.txt through autoit it returns a 0 even if its matching. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 8, 2007 Moderators Share Posted February 8, 2007 when i run the cmd find "text" c:\largefile.txt through autoit it returns a 0 even if its matching.It has to be used properly... how about showing us what you are looking for, and how you wrote it (Just an example) so we can tell you if it was correctly written. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MrCreatoR Posted February 8, 2007 Share Posted February 8, 2007 What for you need run a cmd? use StringInStr or StringRegExp - if you like to read from console, then see in help file Run params: Dim $iline $ConsoleRead = Run(@ComSpec & ' /c find "text" C:\largefile.txt', '', @SW_HIDE, 2) While 1 $iline &= StdoutRead($ConsoleRead) If @error Then ExitLoop WEnd If StringInStr($iline, "text") Then MsgBox(0, "", $iline) Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team 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