Jump to content
Sign in to follow this  
PassionTime2013

Search multiple strings in file using autoit script

Recommended Posts

PassionTime2013

I have file called Test.txt contains

Introduction

License

Installation Directory

Frequently Asked Questions (FAQ)

Credits

History ChangeLog

History of and Developers

Running Scripts

Script Editors

Compiling Scripts

Window Info Tool (Info)

Window Titles and Text (Basic)

Window Titles and Text (Advanced)

Controls

Running under normal user

 

I wanted get multiple string "License", "Script Editors", "Controls","Window Info Tool (AU3Info)" as print ouput with searched lines using autoit

below code I can search only one time, How can I do it for multiple string search.

#include <File.au3>
#include <array.au3>
$file = @ScriptDir & "\file.txt"
$search = "word"

If FileExists($file) Then
$contents = FileRead($file)
If @error Then
MsgBox(0, 'File Error', $file & ' could not be read.')
Else
For $i = 1 To $count
If StringInStr($contents, $search) Then
MsgBox(0, 'found', $file & ' does contain the text "' & $search & '"')
Else
MsgBox(0, 'Not', $file & ' does NOT contain the text "' & $search & '"')
EndIf
Next
EndIf
EndIf

Share this post


Link to post
Share on other sites
Melba23

PassionTime2013,

Welcome to the AutoIt forum. :)

But please pay attention to where you post - the "Developer Chat" section where you started this thread is not for general support questions. I have moved the thread for you, but would ask you to be more careful in future. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
PassionTime2013

Where U moved this thread can u mention url ... thanks

Edited by PassionTime2013

Share this post


Link to post
Share on other sites
Melba23

PassionTime2013,

 

Where U moved this thread

If you do not know, then how did you find it to post? ;)

It is now in "General Help and Support" - your browser address bar will give you the URL if you really need it. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
PassionTime2013

This is the first time I entered this forum I have searched the all the tab Finally I got in "Developer Chat" section in that section  I saw "New Post" then i posted my query, So u told that moved to thread side that's why I asked the Url, :sweating: 

Edited by PassionTime2013

Share this post


Link to post
Share on other sites
Melba23

PassionTime2013,

Now you have found yourself again, would you care to explain more clearly what it is you want to do? It seems that you have a text file containing some of the headings from the AutoIt Help file and you want to print something from it after searching for a word. Is that a good summary? :huh:

If you want to find out how many times a word is included in a text then use StringReplace - the count is returned in @extended as you can see here:

#include <Constants.au3>

$sString = "blah FRED blah blah blah FRED blah blah blah FRED blah blah blah blah FRED blah blah blah FRED blah blah blah"

StringReplace($sString, "fred", "")
$iCount = @extended

MsgBox($MB_SYSTEMMODAL, "Count", "'Fred' appears " & $iCount & " times in the string")
Is that any help? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
PassionTime2013

Thanks for your reply :zorro: 

Sorry I missed some words, Actually I wanted to search multiple strings in a text file which are "License", "Script Editors", "Controls","Window Info Tool (AU3Info)" and need to print that those particular lines

Edited by PassionTime2013

Share this post


Link to post
Share on other sites
Melba23

PassionTime2013,

Then I suggest you put the search terms in an array so you can loop through them easily. Load the file into an array (_FileReadToArray) and then loop through that array checking each line for the required terms - if one of them is present, then copy that line to a new file (FileWriteLine). When all is done you will have a file containing the required lines which you can print at your leisure.

Give it a go and see how you get on - you know where we are if you run into problems. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×