Sign in to follow this  
Followers 0
blizzedout

Match string in file?

10 posts in this topic

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?

Share this post


Link to post
Share on other sites



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 *

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 :whistle: , 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 by MsCreatoR

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

What's wrong with StringInStr()?


[center]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.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by blizzedout

Share this post


Link to post
Share on other sites

i was able to get it to work in cmd prompt but cant seem to get autoit to use it and determine results.

Share this post


Link to post
Share on other sites

StringRegExp()


[center]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.[/center]

Share this post


Link to post
Share on other sites

StringRegExp()

when i run the cmd find "text" c:\largefile.txt through autoit it returns a 0 even if its matching.

Share this post


Link to post
Share on other sites

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.

[center]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.[/center]

Share this post


Link to post
Share on other sites

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)

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

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