Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Remove duplicates separated by commas – GREP or Script help

Explorer ,
Oct 04, 2019 Oct 04, 2019

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

 

 

TOPICS
Scripting
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Mentor , Oct 04, 2019 Oct 04, 2019
No surprise, since it's based on a given samples. Try this ((\w+ )*\w+, )\1 or this ([^,]+, )\1 Slightly different approach, but result ought to be essentially the same.
Translate
Explorer , Oct 07, 2019 Oct 07, 2019

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

...
Translate
Community Expert ,
Oct 04, 2019 Oct 04, 2019

If your data merge is creating this problem, it should be fixable by editing your merge template or your data file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 04, 2019 Oct 04, 2019

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2019 Oct 04, 2019

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.

Screenshot 2019-10-04 12.06.17.pngexpand imageScreenshot 2019-10-04 12.05.34.pngexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 04, 2019 Oct 04, 2019

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Oct 04, 2019 Oct 04, 2019

I'd prefer this AIO:

Find:

(\w+, )\1

Change to:

$1

Repeat Change All untill no matches will be found.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 04, 2019 Oct 04, 2019
Thanks, winterm! When I ran that, my output was this: Black, Black, Yellow, Green, Blue, Blue, Red, Brown, Purple, Purple, Purple. Any idea why?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 04, 2019 Oct 04, 2019
Never mind! I see you have to run it multiple times!! Thanks!!!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 04, 2019 Oct 04, 2019

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Oct 04, 2019 Oct 04, 2019
No surprise, since it's based on a given samples. Try this ((\w+ )*\w+, )\1 or this ([^,]+, )\1 Slightly different approach, but result ought to be essentially the same.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 05, 2019 Oct 05, 2019
Thank you!!!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 07, 2019 Oct 07, 2019
LATEST

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

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines