Thread Tools Display Modes
05-02-14, 07:47 AM   #1
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
SublimeText2 Remove Duplicate

This is a cross post! - Not sure if it belongs in the GAD section...

Just wondering if any other SublimeText 2 users know how to resolve this issue without having to manually delete the repeated/duplicate value:

I have an ungodly amount of lines that need one of the duplicate (1025 and 1151 in this example) values removed.
Code:
s(-1025,1025,{32047, 32048, 32049, 32050, 32051, 32807, 32795},128)
s(1151,1151,{8197, 8176, 8193, 8192, 8175, 31563, 9428, 94044},nil)
I searched around on Stack Overflow and a few other sites and got some major help in regards to other things, but couldn't find anything specific about removing duplicate values in a line/string without screwing up the other values. Any suggestions or plugins?

Cheers!
  Reply With Quote
05-02-14, 11:19 AM   #2
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Hmm, in a regular expression, it would probably be something along the lines of:
Code:
/(\d+),\1/
and replace with
Code:
\1
http://regex101.com/r/gI4uK9
EDIT: or even: http://regex101.com/r/vB1lW4
  Reply With Quote
05-02-14, 11:53 AM   #3
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Originally Posted by ravagernl View Post
Hmm, in a regular expression, it would probably be something along the lines of:
Code:
/(\d+),\1/
and replace with
Code:
\1
http://regex101.com/r/gI4uK9

You is my hero! THANKS!

Last edited by Tactica : 05-02-14 at 11:59 AM.
  Reply With Quote
05-03-14, 03:27 AM   #4
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
I don't know if this is even possible with regex/apend without having to do it manually:
Code:
s(895,"Stormshroud Armor",{15058,21278,23073,30362,12966},1544) --Leather
s(-1266,"Stormshroud Armor (Recolor)",{29141,21458,21708},nil) --Leather
s(-166,"Stormshroud Armor (Recolor)",{10153,10149,10147,10145},nil) --Leather
s(-163,"Stormshroud Armor (Recolor)",{8299,8301,8298,8293,8295},nil) --Leather
s(1759,"Battle",{99157,99158,99159,105779,105792},4) --Mail
s(-1764,"Battle (Lookalike)",{105140,104956,105141,105086,105119},nil) --Mail
s(1763,"Battle (Recolor)",{99081,99082,105086,105119},4) --Mail
s(-1762,"Battle (Lookalike)",{105639,105584,105617},nil) --Mail
s(-1761,"Battle (Recolor)",{99404,105584,105617},4) --Mail
s(-1760,"Battle (Lookalike)",{105800,105779,105792},nil) --Mail
I am trying to place the 895/1759 etc. etc. value to all pieces in a matching name/set:
Code:
s(895,"Stormshroud Armor",{15058,21278,23073,30362,12966},1544) --Leather; 895
s(-1266,"Stormshroud Armor (Recolor)",{29141,21458,21708},nil) --Leather; 895
s(-166,"Stormshroud Armor (Recolor)",{10153,10149,10147,10145},nil) --Leather; 895
s(-163,"Stormshroud Armor (Recolor)",{8299,8301,8298,8293,8295},nil) --Leather; 895
s(1759,"Battle",{99157,99158,99159,105779,105792},4) --Mail; 1759
s(-1764,"Battle (Lookalike)",{105141,105086,105119},nil) --Mail 1759
s(-1763,"Battle (Recolor)",{99081,99082,105086,105119},4) --Mail; 1759
s(-1762,"Battle (Lookalike)",{105639,105584,105617},nil) --Mail; 1759
s(-1761,"Battle (Recolor)",{99404,105584,105617},4) --Mail; 1759
s(-1760,"Battle (Lookalike)",{105800,105779,105792},nil) --Mail; 1759
  Reply With Quote
05-03-14, 05:30 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Not sure if there's a pure regex solution (at least one you can drop into a search/replace dialog) but based on your example it looks like all the "base" sets have positive IDs and the "lookalike" sets have negative ones, so you could reduce the amount of copy/pasting you have to do by regex-ing the positive ID to the end, then just copying it to the ID-less lines below it.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
05-03-14, 09:03 AM   #6
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Originally Posted by Phanx View Post
...based on your example it looks like all the "base" sets have positive IDs and the "lookalike" sets have negative ones, so you could reduce the amount of copy/pasting you have to do by regex-ing the positive ID to the end, then just copying it to the ID-less lines below it.
True, Find+Select then Find All lines containing just a positive value s(####,"...) would work. Just need to capture the first set of numbers! Tried tinkering a bit and this is as far as I got with the expression:
\w[(]\d[0-9]*
This selects s(#### when all I need is the s(####
Using the select line feature would eliminate 708 lines to comment and leave 89 lines to comment!
  Reply With Quote
05-03-14, 02:22 PM   #7
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
I'm not a programmer, so I'm not 100% sure if this will help. But when I'm modifying lua I use Notepad++ it has a find and a find/replace function that make changing every instance of "MOM" to "DAD" simple as clicking the "find next" button then click the "replace" button.

Hope this helps.
Coke

Last edited by cokedrivers : 05-03-14 at 02:29 PM.
  Reply With Quote
05-03-14, 03:04 PM   #8
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by Tactica View Post
This selects s(#### when all I need is the s(####
Using the select line feature would eliminate 708 lines to comment and leave 89 lines to comment!
Try capturing it, also you can use \d+ instead of \d[0-9]* \d+ matches one digit or more.

http://regex101.com/r/mR2fG3
  Reply With Quote
05-03-14, 03:48 PM   #9
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Originally Posted by ravagernl View Post
Try capturing it, also you can use \d+ instead of \d[0-9]* \d+ matches one digit or more.

http://regex101.com/r/mR2fG3
I am a lil confuzzled. Sorry if I am such a nub at these expressions... http://regex101.com/r/mR2fG3 = [a-z]\((\d+) and \w[(]\d+ which both capture the same "s(1759" when I need just the "1759" Also, this is for regexp future reference.

Still trying to figure out how to copy all the different line values, i.e. "s(1759", "s(892" etc. etc. throughout the entire ST2 document and then paste them at the end of their respective line. Any suggestion as to the proper method?

EDIT:
Code:
local comment, group
print((([[
s(1759,"B 1",{99168,99157,99158,99159,105779,105792},4)
s(-1764,"B 2 (L)",{105819,105140,104956,105141,105086,105119},nil)
s(-1763,"B 3 (R)",{99086,99080,99081,99082,105086,105119},4)
s(-1762,"B 4 (L)",{105432,105638,105454,105639,105584,105617},nil)
s(-1761,"B 5 (R)",{99406,99402,99403,99404,105584,105617},4)
s(-1760,"B 6 (L)",{105183,105809,105754,105800,105779,105792},nil)
s(1753,"C",{105161,99108,99109,99104,105784,105790},64)
s(-1755,"C (R)",{105410,99352,99353,99354,105597,105598},64)
s(-1754,"C (L)",{105329,105161,105259,105404,105755,105784,105790},nil)
]]):gsub('(s%((.-),"(%w+).-)\n',
   function(line, next_comment, next_group)
      if group ~= next_group then
         group = next_group
         comment = next_comment
      end
      return line..' -- '..comment..'\n'
   end
)))
^ Works somewhat. It matches s(1629,"Plate of the All-Consuming Maw" with the same itemset# (1629) as s(1458,"Plate of Resounding Rings" due to the "Plate" name.

Last edited by Tactica : 05-03-14 at 04:11 PM.
  Reply With Quote
05-03-14, 06:24 PM   #10
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
You might try http://regex101.com/r/bC3wS3 with Phanx suggestion above
  Reply With Quote
05-04-14, 10:22 AM   #11
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
I am posting this to share with others for reference and so others could critique the regex I used to accomplish everything. Maybe someone will find this helpful.

Here is the example code:
Code:
s(544,"Ahn'Kahar Blood Hunter's Battlegear",{50118,50789,50762,50812},4)--544
s(-469,"Ahn'Kahar Blood Hunter'sBattlegear(Lookalike)",50413,49952,50071,50000},nil) --544
s(-470,"Ahn'Kahar Blood Hunter's Battlegear (Lookalike)",{51877,51911,51853,51914},nil) --544
s(-471,"Ahn'Kahar Blood Hunter's Battlegear (Lookalike)",{51002,51566,51325,50789},nil) --544
s(-545,"Ahn'Kahar Blood Hunter's Battlegear (Recolor)",{50979,54577,51151,51153,51914,51935},4)  --544
s(-546,"Ahn'Kahar Blood Hunter's Battlegear (Recolor)",{,51289,50655,50688,50711},4) --544
FYI:
  • Find What:
  • Replace With:
All links take you to regex101 examples!
This was done in Sublime Text 2.

------------------------------------------------------------------------------
  1. Remove duplicate id value: s(1234,1234,
    • (\d+),\1
    • \1
    Here


  2. Comment with their respective ID:
    s(1059,"Amani Mail",{,69561,69590,94216},nil) --1059
    s(-1060,"Amani Mail (Recolor)",{33535,94079,94083,94078},nil) --1059
    • s\((?<!\-)(\d+)(.+\n)(?:((?:s\((?=\-).+\d+\n)+)|(s\((?=\-).+))+
    • s($1$2$3$4 --$1


  3. Fix for above which may produce:
    --1059s(1059,"Amani Mail",{,69561,69590,94216},nil) --1059
    • \s?--.+(?=s\()
    Here


  4. To add --####;Mail after:
    --####
    • (--+.*)
    • \1; Cloth
    Here


  5. To find all comments:
    --1234
    • (--+.*)
    • \1
    Same as above, use Find All


  6. Copy s(####) to --Comment; ####
    • ([a-z]\((\d+).*)
    • \1; \2
    Here



  7. To find s(###) not s(-1234
    • \w\(\d
    Here

Last edited by Tactica : 05-04-14 at 01:46 PM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » SublimeText2 Remove Duplicate

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off