Jump to content

Search in Text the report


Go to solution Solved by jguinch,

Recommended Posts

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

 

 

Link to comment
Share on other sites

  • Moderators

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?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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

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

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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

Link to comment
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!

Link to comment
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

Link to comment
Share on other sites

  • Solution

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)
Link to comment
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)

 

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

it should not happend.

it Works!, thanks

Edited by usera
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...