Jump to content
Sign in to follow this  
usera

Search in Text the report

Recommended Posts

usera

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
JLogan3o13

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?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Damein

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
  • Like 1

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
JLogan3o13

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
  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
usera

 

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
usera

 

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
usera

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
JLogan3o13

Have you tried what I posted?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
jguinch

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)
  • Like 1

Share this post


Link to post
Share on other sites
usera

Have you tried what I posted?

 

yes, I did, but no result

Share this post


Link to post
Share on other sites
usera

 

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
usera

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.