halcyon627

Find and display text in a text file

10 posts in this topic

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! :)

Share this post


Link to post
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

1 person likes this

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

When you code the command " If Variable %T1% contains "S-Shata" ", there is a checkbox option to ignore case. 

Share this post


Link to post
Share on other sites
2 hours ago, rberq said:

When you code the command " If Variable %T1% contains "S-Shata" ", there is a checkbox option to ignore case. 

I feel stupid now lol

i totally missed that checkbox. Cheers! 

Share this post


Link to post
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 

Share this post


Link to post
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

Share this post


Link to post
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%"

1 person likes this

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

We have drifted a bit from the original topic for this thread but ...

Linux, Unix and MacOS use LF as a line terminator. As mentioned, Windows uses CRLF. This difference can cause issues with files retrieved from different systems.

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