1. #1
    Field Marshal Tactica's Avatar
    Join Date
    Mar 2014
    Location
    9942 Apophis
    Posts
    85

    SublimeText2 Remove Duplicate

    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!
    Last edited by Tactica; 2014-05-02 at 01:43 PM.
    In a cult, there is a person at the top who knows it's a scam. In a religion, that person is dead.

  2. #2
    My guess without experience of the editor would be to do a find/replace, of say "1151,1151" to be replaced with just "1151,".
    That is how I would do it.

    Edit, would only work for one value.
    If it is just those two values you state then that would work, not otherwise.
    Last edited by ComputerNerd; 2014-05-02 at 03:30 PM.
    Quote Originally Posted by DeadmanWalking View Post
    I don't understand why we don't have flying so they tell us we will have convenient flight points. Immersion and danger? Here take some coins and fly me there while I read facebook or go take a poop.
    Quote Originally Posted by Reinaerd View Post
    T'is good to see there are still people valiantly putting the "Ass" in assumption.

  3. #3
    Never used it, but finding duplicate text within a line doesn't sound like a common feature for a text editor.

    Can you write a little clean up script to check for and remove dupes?
    Quote Originally Posted by Elrandir View Post
    My starfall brings all the mobs to the yard.
    Laurellen - Druid Laurellin - Deathknight

  4. #4
    I suspect ST2 supports Perl-style regular expressions, in which case you could regexp "([0-9]+),\1" => "\1", since you are able to use backreferences in matching as well as replacement. Ah, yes, they use Boost regex, which is Perl-compatible, so while not strictly regex any longer, can do that.

    So, yeah, there you go: regexp search-and-replace with a reference back to the previous match to find duplicates. Enjoy.

  5. #5
    Field Marshal Tactica's Avatar
    Join Date
    Mar 2014
    Location
    9942 Apophis
    Posts
    85
    Quote Originally Posted by SlippyCheeze View Post
    So, yeah, there you go: regexp search-and-replace with a reference back to the previous match to find duplicates. Enjoy.
    Thanks, but since I am so new to ST2 I don't think I am doing it right.

    Using Winwoes: Ctrl+H to open F&R, Alt+R for Regex or (Ctrl+Shift+P then Filter or Fold with Regex?)


    - - - Updated - - -

    ravagernl posted a different format which also works: http://regex101.com/r/gI4uK9

    Find: (\d+),\1
    Replace: \1
    In a cult, there is a person at the top who knows it's a scam. In a religion, that person is dead.

  6. #6
    Oh, sorry -- I suspect that you would need to use \[0-9\]+ or something to make it work; basically, there are about a million different regex syntaxes, and I didn't read that one closely enough. The \d thing means "any number", which is also what I tried to say with [0-9], so they are roughly equal. Except, y'know, mine didn't work, haha.

    (Actually, there are only about 10 different flavours, but they all have these minor differences and I hate them all, because you never know which one is right this time.

  7. #7
    -- I suspect that you would need to use \[0-9\]+ or something to make it work
    There's the old truism: you have a problem and thought "I'll use regex". Now you have two problems.

    Escaping [] in regex would be madness but stranger things have happened. In his case the problem was that OP misinterpreted your message. Look at the screenshot where it says Find: "([0-9]+),\1" => "\1" while the replace box is left empty. You meant for him to read => as "Replace with:" but I guess that wasn't the message he took from your post.
    • Find: ([0-9]+),\1
    • Replace: \1
    That should have been should be correct. Maybe he was expect a vim-style ex command like: :'<,'>s /\(\d+\),\1/\1/gc.
    Last edited by evn; 2014-05-02 at 11:43 PM.
    A new UI series for 5.2Steal my old UILearn about WeakAuras • Nobody to raid with right now so no PVE videos.

  8. #8
    Field Marshal Tactica's Avatar
    Join Date
    Mar 2014
    Location
    9942 Apophis
    Posts
    85
    Quote Originally Posted by evn View Post
    You meant for him to read => as "Replace with:" but I guess that wasn't the message he took from your post.
    • Find: ([0-9]+),\1
    • Replace: \1
    That should have been should be correct. Maybe he was expect a vim-style ex command like: :'<,'>s /\(\d+\),\1/\1/gc.
    I'm an idiot...didn't realize that was the format...

    • Find: ([0-9]+),\1
    • Replace:\1
    ^ This works too...Thanks guys!

    - - - Updated - - -

    Another question for you guys. Need to sort lines by the first letter and then by the first number within the line, for two separate sorts:
    Code:
    s(-450,"Volcanic Vestments (Lookalike)",{69941,71027,71042,71009,71340,71254,70985,71356},nil) --Mail 
    s(-451,"Flamewaker's Battlegear (Lookalike)",{69939,71315,71005,70736,71018,71255,71365,71030},nil) --Mail 
    s(-456,"Scourgestalker Battlegear (Recolor)",{45711,45941,45679,45895,46019,46346},nil) --Mail 
    s(-429,"Worldbreaker Garb (Recolor)",{45837,45563,45554,45544,45259,45474,45187},nil) --Mail 
    s(-466,"Frost Witch's Garb (Lookalike)",{49900,50202,50059,50971,50064,53488,51873,51929},nil) --Mail
    Which command would I need to accomplish this? Thanks in advance!
    Last edited by Tactica; 2014-05-03 at 03:27 AM.
    In a cult, there is a person at the top who knows it's a scam. In a religion, that person is dead.

  9. #9
    I'm not a sublimetext user but I check the manual and didn't see an obvious way to do it. I'm not 100% sure what you're trying to accomplish, but using the Sort utility from within my editor with %!sort -k1,1 -k4,3n turned this:
    Code:
    f(-450,"Volcanic Vestments (Lookalike)",{69941,71027,71042,71009,71340,71254,70985,71356},nil) --Mail
    x(-451,"Flamewaker's Battlegear (Lookalike)",{69939,71315,71005,70736,71018,71255,71365,71030},nil) --Mail
    a(-456,"Scourgestalker Battlegear (Recolor)",{45711,45941,45679,45895,46019,46346},nil) --Mail
    a(-429,"Worldbreaker Garb (Recolor)",{45837,45563,45554,45544,45259,45474,45187},nil) --Mail
    c(-466,"Frost Witch's Garb (Lookalike)",{49900,50202,50059,50971,50064,53488,51873,51929},nil) --Mail
    into this:
    Code:
    a(-429,"Worldbreaker Garb (Recolor)",{45837,45563,45554,45544,45259,45474,45187},nil) --Mail
    a(-456,"Scourgestalker Battlegear (Recolor)",{45711,45941,45679,45895,46019,46346},nil) --Mail
    c(-466,"Frost Witch's Garb (Lookalike)",{49900,50202,50059,50971,50064,53488,51873,51929},nil) --Mail
    f(-450,"Volcanic Vestments (Lookalike)",{69941,71027,71042,71009,71340,71254,70985,71356},nil) --Mail
    x(-451,"Flamewaker's Battlegear (Lookalike)",{69939,71315,71005,70736,71018,71255,71365,71030},nil) --Mail
    so sorting on the first letter, then the first 3-digits.

    Sort is a standard utility on any *NIX system so you could even just run it in your terminal emulator if sublime text doesn't provide an easy way to funnel your text buffer through a shell command. I'm not sure how you'd duplicate this functionality if you're using the Windows version, maybe somebody else can chime in.
    A new UI series for 5.2Steal my old UILearn about WeakAuras • Nobody to raid with right now so no PVE videos.

  10. #10
    Field Marshal Tactica's Avatar
    Join Date
    Mar 2014
    Location
    9942 Apophis
    Posts
    85
    I found a plugin but I think it needs tweaking. Does the job tho! Final question, and I don't know if this is even possible without having to do it manually:
    Code:
    s(895,"Stormshroud Armor",{15056,15057,15058,21278,23073,30362,12966},1544) --Leather
    s(-1266,"Stormshroud Armor (Recolor)",{6433,22409,29141,21458,21708},nil) --Leather
    s(-166,"Stormshroud Armor (Recolor)",{29804,28051,10152,10150,10153,10149,10147,10145},nil) --Leather
    s(-163,"Stormshroud Armor (Recolor)",{54727,8300,8296,8299,8301,8298,8293,8295},nil) --Leather
    I am trying to place the 895 value to all pieces in a matching name/set:
    Code:
    s(895,"Stormshroud Armor",{15056,15057,15058,21278,23073,30362,12966},1544) --Leather; 895
    s(-1266,"Stormshroud Armor (Recolor)",{6433,22409,29141,21458,21708},nil) --Leather; 895
    s(-166,"Stormshroud Armor (Recolor)",{29804,28051,10152,10150,10153,10149,10147,10145},nil) --Leather; 895
    s(-163,"Stormshroud Armor (Recolor)",{54727,8300,8296,8299,8301,8298,8293,8295},nil) --Leather; 895
    Any tricks to simplify?

    - - - Updated - - -

    Quote Originally Posted by Phanx View Post
    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.
    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!
    In a cult, there is a person at the top who knows it's a scam. In a religion, that person is dead.

  11. #11
    Field Marshal Tactica's Avatar
    Join Date
    Mar 2014
    Location
    9942 Apophis
    Posts
    85
    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.

    ------------------------------------------------------------------------------
    • Remove duplicate id value: s(1234,1234,

      -(\d+),\1
      -\1

      Here

    • 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


    • Fix for above which may produce:
      --552s(900,"Blessed Garb",{43082,43081,43083,43080},nil)
      \s?--.+(?=s\()

      Here

    • To add --####;Mail after:
      --####

      (--+.*)
      \1; Cloth

      Here

    • To find all comments:
      --1234
      (--+.*)
      \1

      Same as above, use Find All

    • Copy s(####) to --Comment; ####

      ([a-z]\((\d+).*)
      \1; \2
      Here


    • To find s(###) not s(-1234

      \w\(\d

      Here
    Last edited by Tactica; 2014-05-13 at 01:11 PM.
    In a cult, there is a person at the top who knows it's a scam. In a religion, that person is dead.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •