Copy link to clipboard
Copied
I'm working on a catalog using data merge. The data is coming in like this:
Black, Black, Black, Yellow, Yellow, Green, Blue, Blue, Blue, Blue, Red, Red, Brown, Purple, Purple, Purple, Purple, Purple
Can someone help with a Script or GREP that will remove the duplicates and leave me with this?:
Black, Yellow, Green, Blue, Red, Brown, Purple
Also, there are many more color combinations and the duplication can be up to 12 times in a string of text.
Any help from the community is greatly appreciated!!
Final AppleScript based on winterm's GREP. I added the repeat loop and placed it at 12 because 12 is the maximum number of times a color will repeat in my project. If this is used as a GREP only ((\w+ )*\w+, )\1, you have to run it multiple times to work.
tell application "Adobe InDesign CC 2019"
repeat 12 times
set find grep preferences to nothing
set change grep preferences to nothing
set find what of find grep preferences to "((\\w+ )*\\w+, )\\1"
set change to of change grep preferences to "$1"
cha
...Copy link to clipboard
Copied
If your data merge is creating this problem, it should be fixable by editing your merge template or your data file.
Copy link to clipboard
Copied
Unfortunately, it's being created in the Excel file that I'm grabbing the data from. According to our Excel guru it can't be easily fixed on his end.
Copy link to clipboard
Copied
Here's a GREP, but it will have to run separately for each color that has duplicates in the document.
Just be sure to add the space in the find and replace fields.
Copy link to clipboard
Copied
Thanks! I'll give that a try!! That's the starting point I was looking for, I should be able to write an AppleScript based on that.
Copy link to clipboard
Copied
I'd prefer this AIO:
Find:
(\w+, )\1
Change to:
$1
Repeat Change All untill no matches will be found.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Any fix if there are also TWO or THREE words separated by commas? If example: "Light Blue Grey, Light Blue Grey, Light Blue Grey, Dark Red, Dark Red, Green, Green, Green, Green"
The GREP doesn't seem to work in that instance.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Final AppleScript based on winterm's GREP. I added the repeat loop and placed it at 12 because 12 is the maximum number of times a color will repeat in my project. If this is used as a GREP only ((\w+ )*\w+, )\1, you have to run it multiple times to work.
tell application "Adobe InDesign CC 2019"
repeat 12 times
set find grep preferences to nothing
set change grep preferences to nothing
set find what of find grep preferences to "((\\w+ )*\\w+, )\\1"
set change to of change grep preferences to "$1"
change grep
set find grep preferences to nothing
set change grep preferences to nothing
end repeat
end tell