Jump to content
Macro Express Forums

Find and display text in a text file


halcyon627

Recommended Posts

I'm slowly learning more and more about Macro Express 3, and need a little help to fully complete this task I want done.

I essentially have a text file that contains a list of artists/tracks that have already been processed. When it comes time to process new artists/tracks, I want to see if I have done them already by checking it against this file. I know how to search a text file for a particular search string, but what I want to do is display everything on a particular line where matching text is found? For instance... if I search for "S-Shata - My Way", I want it to display the full line where that text is located. I can get the position of the text in the text file, but how does that translate to displaying the full line? I"m sure this is easy, but please let me know! :)

Link to comment
Share on other sites

Try this: Use Text File Begin Process to get each line, sequentially, into a text variable.  (One line on each pass through the loop defined by Text File Begin Process / Text File End Process).

When the line is in the text variable (T1 for example), if variable T1 contains "S-Shata" then display the whole of T1 (the whole line) with the Text Box Display command. 

Text File Begin Process: "filename.txt"
  If Variable %T1% contains "S-Shata"
    Text Box Display: %T1%
  End If
Text File End Process

  • Like 1
Link to comment
Share on other sites

5 hours ago, rberq said:

Try this: Use Text File Begin Process to get each line, sequentially, into a text variable.  (One line on each pass through the loop defined by Text File Begin Process / Text File End Process).

When the line is in the text variable (T1 for example), if variable T1 contains "S-Shata" then display the whole of T1 (the whole line) with the Text Box Display command. 

Text File Begin Process: "filename.txt"
  If Variable %T1% contains "S-Shata"
    Text Box Display: %T1%
  End If
Text File End Process

This worked like a charm! Thanks so much!

I had to tweak it a little bit to allow for multiple search results, but I got those ironed out quick.

Do you know if there is a way to make the Text File Process not be case sensitive? If the text isn't EXACTLY the same, it won't get flagged as a result. I can simply Capitalize Each First Letter, but all lowercase would be much quicker productivity wise lol

Link to comment
Share on other sites

Don't feel dumb.  There are lots of neat things in ME that are easy to miss.  For example, the Variable Modify String command has options to change an entire string to lower or upper case.  That would be another way of doing your comparison.  But I didn't remember the options were there until I looked for them a few minutes ago.:o 

Link to comment
Share on other sites

Yes, there are always more than one way to solve a problem lol

For instance, I didn't know how to append a carriage return to a text file, so I made a text file with 2 carriage returns, named it spacer, assigned it to a variable and appended that lol

might be an easier way, but that worked haha

Link to comment
Share on other sites

Here are two other ways to append a carriage return to a text file. Note that in Windows lines are terminated with two control characters: CR LF

1. The "Variable Modify String: Append %T1% to Text File" has a checkbox that says to include CR/LF. You could use this with an empty variable to append only CRLF.

2. This is what I do. At the top of my macro I include these:

Variable Set %T13% to ASCII Char of 13
Variable Set %T10% to ASCII Char of 10

Then when setting strings I do something like this: Variable Set String %T1% "SomeValue%T13%%T10%"

  • Like 1
Link to comment
Share on other sites

45 minutes ago, Samrae said:

Here are two other ways to append a carriage return to a text file. Note that in Windows lines are terminated with two control characters: CR LF

1. The "Variable Modify String: Append %T1% to Text File" has a checkbox that says to include CR/LF. You could use this with an empty variable to append only CRLF.

2. This is what I do. At the top of my macro I include these:

Variable Set %T13% to ASCII Char of 13
Variable Set %T10% to ASCII Char of 10

Then when setting strings I do something like this: Variable Set String %T1% "SomeValue%T13%%T10%"

Oh ok! So both our used in conjunction for a single carriage return? That's smart! I tried to go the ascii route but didn't know how to assign it to a variable. This will work splendid :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...