Now, there are 4 lines here, but only 3 different ‘Applications’.
So, my question is, can I search the variable for multiple instances of ‘Application “A”’ and do something with that? (i.e. delete that line from the variable)
the text will be different each time, so i'm not sure how I would do it with the 'Search & Replace' action.
Here is one simple approach that should work OK for a short list (say < 100 lines).
It works fast on 5-6 lines, but will probably bog down with hundreds/thousands of lines since it replaces the entire string when it finds a dup -- not very efficient.
But it provides a KM only solution that requires only 2 Actions.
EDIT: See VER: 2.0 2020-06-23 below which provides a much better JavaScript solution.
Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.
Here is another alternative, using the power of JavaScript Arrays and Sets in JavaScript for Automation (JXA).
This is my preferred solution, and should work well even for thousands of lines.
Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.
I think there's a mistake in @JMichaelTX's macro above. His original Regular Expression search:
has four tagged sequences but he only uses three of them in the replacement string. I think his replacement string will end up deleting everything from the second instance of %Local__Line% to the end of the list.
The fix is simple, the replacement should be:
\1\2\3\4
which will insert:
\1: The beginning of the list, before the first instance of %Local__Line%
\2: The first instance of %Local__Line%
\3: Everything up to the second instance of %Local__Line%
\4: Everything after the second instance of %Local__Line%
I hope this helps. It's a great example of using Regular Expressions.
I posted a macro a few years ago that rapidly de-dupes a list, but also extracts the dupes:
Using the long list in that demo (240 words), it takes it about 0.3 seconds to process and display all three lists (original, dupes, and de-duped). No regex at all, no Javascript, just two Unix commands (sort and uniq).