Find text within a file

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
lebrocoli
Pro Scripter
Posts: 53
Joined: Tue Sep 06, 2005 9:28 pm

Find text within a file

Post by lebrocoli » Wed Oct 17, 2007 5:25 pm

Hi,

After playing around, I decided to send my DOS output to a file. Then I open the file in Notepad. All good.

Now, I have seen a lot of post that tells how to read lines or files or replace or concatenate but not much on how to find whar you are looking for.

The closest thing I found is the function 'FindWindowwithtext'. What I would like to have instead is more the opposite like 'FindTextWithinWindow'.

The point is that I don't want to search for a window. I already have my text file that I know its filename, I just want to search for some text within that file.

Any hint?

Thanks

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed Oct 17, 2007 5:48 pm

I wouldn't play with notepad. Use ReadFile> to read the text into a variable, and use Position> to find text, use MidStr> and StringReplace> to manipulate it. You'll find lots of useful commands in the String Handling section of the Command Reference.

lebrocoli
Pro Scripter
Posts: 53
Joined: Tue Sep 06, 2005 9:28 pm

Post by lebrocoli » Wed Oct 17, 2007 6:39 pm

Just tried it. It works like a charm!

Thanks a lot !

nodochau
Pro Scripter
Posts: 131
Joined: Wed Jan 16, 2019 12:59 pm

Re: Find text within a file

Post by nodochau » Thu Jan 17, 2019 3:22 pm

It is very interested. Please tell me more details about searching text. Let say if I want to search for "tool motions" in entire file what the code will be? I am new with macro scheduler.
ReadFile>....
Position>tool motion,'STRING",1,11,var
If>var>0
MessageModal>Found
Endif.
I want to know what will I assign the string in position command.

Thanks

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts