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

Remove duplicates separated by commas – GREP or Script help

Explorer ,
Oct 04, 2019 Oct 04, 2019

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

 

 

TOPICS
Scripting

Views

2.1K

Translate

Translate

Report

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.

Votes

Translate

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

...

Votes

Translate

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

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.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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.

Screenshot 2019-10-04 12.06.17.pngScreenshot 2019-10-04 12.05.34.png

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thanks, winterm! When I ran that, my output was this: Black, Black, Yellow, Green, Blue, Blue, Red, Brown, Purple, Purple, Purple. Any idea why?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Never mind! I see you have to run it multiple times!! Thanks!!!!

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank you!!!!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

 

 

Votes

Translate

Translate

Report

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