Sign in to follow this  
Followers 0
frew

Show matching text files matching whole word in line(s) only?

4 posts in this topic

Hello,

I've cataloged a bunch of .wav files amongst lots of other kinds of files over the years in a collection of text files.

I'm trying to figure out how to write a script that will

search through about 900 text files, which are all in the same folder,

and show me only the names of the text files that contain

one or more lines that contain the exact string "4.wav"

So, for example, here's what some text files might contain in them:

(textfile_1.txt is a match, because it contains one or more lines that contain

exactly "4.wav" with nothing else in that line.)

textfile_1.txt

4.wav

104.wav

lake.txt

(textfile_2.txt is not a match, because there's no line that

contains exactly "4.wav")

textfile_2.txt

104.wav (104.wav is not exactly 4.wav)

autumn.txt

Thanks for any help with this.

Share this post


Link to post
Share on other sites



Since you didn't state what the lines look like this is just a guess.

$sFile = "textfile_2.txt" ;; you will probably be getting this by looping through an array or some similar manner like FileFindFirst/NextFile()
If StringRegExp(FileRead($sFile), "(?i)(?m:^)4\.wav") Then
    MsgBox(0, "Result", "We have a match")
Else
   MsgBox(0, "Result", "No match")
EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Wow !

Very nice! It works very well.

I appreciate your help with this.

By the way, the lines in the text files look like these examples, but with many more lines in them:

textfile_1.txt (the file named textfile_1.txt has these kinds of lines in them)

4.wav

104.wav

lake.txt

textfile_2.txt (the file named textfile_2.txt has these kinds of lines in them)

104.wav

autumn.txt

Also, wow, I wish I could get the regular expression stuff, but it just seems way difficult for now.

Any links to known good basic regular expression tutorials perhaps?

Thanks again!

frew

Share this post


Link to post
Share on other sites

With that type of layout for the text files; the expression I gave you should always work and I'm glad it works for you.

If you look in my signature there is a PCRE toolkit that allows you to test RegExps as used in AutoIt. The help menu contains links to a few resources for RegEx and there is a small built-in library of sample expressions. You can also create new libraries in which you would store expressions that you want to save for future reference.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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