Using GREP to find duplicated instances of a string?

1,071 views
Skip to first unread message

kukubura

unread,
May 27, 2011, 9:11:00 AM5/27/11
to TextWrangler Talk
I have a syntax of tracking code for URLs that uses unique numerical
IDs but sometimes when combining various templates the unique IDs end
up being... not so unique. I'd like to be able to use GREP to find
duplicate strings within the document. The syntax for the unique ID
portion is ##2002## with each ID using a differen 4 digit number. How
can I look for duplicates? Can it be done? Thanks!

kukubura

unread,
May 27, 2011, 9:18:27 AM5/27/11
to TextWrangler Talk
So far this is what I have:

(##\d{4}##){2,}?

But they have to be one after the other and I need it to look through
the entire document for dupes...

Steve Kalkwarf

unread,
May 27, 2011, 9:48:19 AM5/27/11
to textwr...@googlegroups.com
On May 27, 2011, at 9:18 AM, kukubura wrote:

> So far this is what I have:
>
> (##\d{4}##){2,}?
>
> But they have to be one after the other and I need it to look through
> the entire document for dupes...


Text menu -> Process Duplicate Lines

You'll probably need to tweak your pattern.

Steve

kukubura

unread,
May 27, 2011, 10:37:36 AM5/27/11
to TextWrangler Talk
That's awesome, thanks. All I need to use for the pattern is ##\d{4}##

I wish I could utilize this feature in the regular search though,
since I have a huge long pattern that searches for tons of stuff and
I'd love to incorporate this into. Barring that, however, this works
great.

Thomas Fischer

unread,
May 27, 2011, 10:48:38 AM5/27/11
to textwr...@googlegroups.com
Hi,

you might try a Unix filter for that. There is actually a "Kill duplicates" script in the #! menu as far as I know (it is on my machine).

Thomas

Reply all
Reply to author
Forward
0 new messages