Sign in to follow this  
Followers 0
Dethredic

Search a document for a spesific line

8 posts in this topic

How can i search a document for a specific line?

If the line exists I need the line number.


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites



If the line exists I need the line number.

google grep ;or learn the windows find command.

'pure autoit' solutions exist, but they will be slower than writing a wrapper around grep or find.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

#include <file.au3>
Dim $aRecords, $find = "this word.. or phrase", $search = "filename.txt"
If Not _FileReadToArray($search,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    If StringInStr($aRecords[$x], $find) Then Msgbox(0,'Record:' & $x, $aRecords[$x])
Next

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks again Val, you have been so helpful tonight (its night for me)

EDIT - quick thing

-What tells me if the line exists?

-What tells me what line it is?

Will this work with a non .txt file? The file in need to search is .js

Edited by Dethredic

"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

Thanks again Val, you have been so helpful tonight (its night for me)

EDIT - quick thing

-What tells me if the line exists?

-What tells me what line it is?

Will this work with a non .txt file? The file in need to search is .js

I gave you a little time to answer your own question...

how did it do???

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Well i am getting the error reading array.

I do not know if it will work with the .js and therefore a can't figure out the other two


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

ok... i tested this, and it worked fine

#include <file.au3>

; type in the file you want to look in here 
Dim $search = "C:\test.txt"

; type in the word/phrase you want to find here
Dim $find = "data"

Dim $aRecords
If Not _FileReadToArray($search,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    If StringInStr($aRecords[$x], $find) Then Msgbox(0,'Record:' & $x, $aRecords[$x])
Next

.... and i have a .js file that is text and it worked also

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks, it was just a typo in the file location


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

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