Sign in to follow this  
Followers 0
usera

Search in Text the report

14 posts in this topic

Greeting,

I have 2 files, "FILE1" is the include keyword that I to search in "FILE2"

for example "FILE1"

     keyword1

     keyword2

     keyword3

     keyword4

     keyword5

 

example for "FILE2"

     blah, blah, keyword1, blah, blah

     blah blah, keyword2, blahblahblah

     keyword3, blahblahblah

   ...

how can I write a AU3

to show that FILE2 has keyword1, has keyword2, but not keyword5

Thanks

usera

 

 

Share this post


Link to post
Share on other sites



Are they both flat text files, or is the first like an .ini? Does FILE1 have only that keyword on each line, or other data you would need to sift through?


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

This should get you started.

I advise you to read the help file a bit more, pretty basic stuff.

#include <Array.au3>

Local $KeyWordArray[6]

$KeyWordArray[1] = "Test"
$KeyWordArray[2] = "Test2"
$KeyWordArray[3] = "Test3"
$KeyWordArray[4] = "Test4"
$KeyWordArray[5] = "Test5"

$File = FileOpen("x")

$FileRead = FileRead($File)

For $i = 1 To 5
    If StringInStr($FileRead, $KeyWordArray[$i]) Then
        MsgBox(0, "Found", "Found the keyword" & @CRLF & $KeyWordArray[$i])
    EndIf
Next
1 person likes this

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

I agree with J1, didn't realize you had been here so long, usera. You should know by now to put some effort in before you post.

As I worked this up anyway, this is how I would do it as opposed to Damein's method.

$aFile1 = FileReadToArray(@DesktopDir & "\FILE1.txt")
$aFile2 = FileReadToArray(@DesktopDir & "\FILE2.txt")

    For $keyword In $aFile1
        For $line In $aFile2
            If StringInStr($line, $keyword) Then MsgBox(0, "", $keyword & " found!")
        Next
    Next
1 person likes this

When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

 

I agree with J1, didn't realize you had been here so long, usera. You should know by now to put some effort in before you post.

As I worked this up anyway, this is how I would do it as opposed to Damein's method.

$aFile1 = FileReadToArray(@DesktopDir & "\FILE1.txt")
$aFile2 = FileReadToArray(@DesktopDir & "\FILE2.txt")

    For $keyword In $aFile1
        For $line In $aFile2
            If StringInStr($line, $keyword) Then MsgBox(0, "", $keyword & " found!")
        Next
    Next

 

thanks, do not know how to do it, that is why ask

any way thanks

usera

Share this post


Link to post
Share on other sites

 

This should get you started.

I advise you to read the help file a bit more, pretty basic stuff.

#include <Array.au3>

Local $KeyWordArray[6]

$KeyWordArray[1] = "Test"
$KeyWordArray[2] = "Test2"
$KeyWordArray[3] = "Test3"
$KeyWordArray[4] = "Test4"
$KeyWordArray[5] = "Test5"

$File = FileOpen("x")

$FileRead = FileRead($File)

For $i = 1 To 5
    If StringInStr($FileRead, $KeyWordArray[$i]) Then
        MsgBox(0, "Found", "Found the keyword" & @CRLF & $KeyWordArray[$i])
    EndIf
Next

 

thank you very much!

Share this post


Link to post
Share on other sites

Are they both flat text files, or is the first like an .ini? Does FILE1 have only that keyword on each line, or other data you would need to sift through?

 

Thanks for ask

both flat text, yes, FILE1 have only that keyword on each line

Share this post


Link to post
Share on other sites

Now, ask yourself the question whether you want the keyword "test" to be found in the string "testing".

And so, do not use StringInStr...

#Include <Array.au3>

Local $aKeywords = FileReadToArray("file1.txt")
Local $sContent = FileRead("file2.txt")

Local $aResult[ UBound($aKeywords) ][2]

For $i = 0 To UBound($aResult) - 1
    $aResult[$i][0] = $aKeywords[$i]
    $aResult[$i][1] = StringRegExp($sContent, "\b" & $aResult[$i][0] & "\b") ? "found" : "not found"
Next

_ArrayDisplay($aResult)
1 person likes this

Share this post


Link to post
Share on other sites

Have you tried what I posted?

 

yes, I did, but no result

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

 

Now, ask yourself the question whether you want the keyword "test" to be found in the string "testing".

And so, do not use StringInStr...

#Include <Array.au3>

Local $aKeywords = FileReadToArray("file1.txt")
Local $sContent = FileRead("file2.txt")

Local $aResult[ UBound($aKeywords) ][2]

For $i = 0 To UBound($aResult) - 1
    $aResult[$i][0] = $aKeywords[$i]
    $aResult[$i][1] = StringRegExp($sContent, "\b" & $aResult[$i][0] & "\b") ? "found" : "not found"
Next

_ArrayDisplay($aResult)

 

"You want the keyword "test" to be found in the string "testing"

it should not happend.

it Works!, thanks

Edited by usera

Share this post


Link to post
Share on other sites

lol

Not a chance, not even after 7 years.

 

LOL, still learning

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