ULX

Author Topic: Help with bulk deletion  (Read 2891 times)

0 Members and 1 Guest are viewing this topic.

Offline Bryantdl7

  • Jr. Member
  • **
  • Posts: 86
  • Karma: -2
Help with bulk deletion
« on: September 22, 2015, 10:23:24 AM »
So I am trying to find a way to delete all strings that contain "new" in the script structure below
Code: [Select]
"STEAM_0:0"
{
"name" "mX"
"deny"
{
}
"allow"
{
}
"group" "new"
}
However, as you can tell I am working with steam ID's so it is not as simple as imputting it into ms word and doing a replace action, I want to delete everything I put inside that code box above. I was wondering if anyone knows of a program that can delete the entire string if it contains a certain variable, such as "group"   "new"
I am cleaning out my users.txt file as it has over 41 thousand lines, and i want to quickly delete everyone from the database while saving my staff from being deleted.

If I confused you guys I can try and explain it better
« Last Edit: September 22, 2015, 10:25:55 AM by Bryantdl7 »



Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Help with bulk deletion
« Reply #1 on: September 23, 2015, 12:12:32 PM »
Use notepad++'s replace feature. It accepts regex expressions and you can just replace it with nothing.

Code: [Select]
"STEAM_0:(0|1):\d+"\s\n{\n\s matches a steamid followed by the first brace and some spaces and newlines
Code: [Select]
"deny"\s\n\s{\n\s\}\n\s matches "deny" followed by some spaces, new lines, and braces
Code: [Select]
"allow"\s\n\s{\n\s\}\n\s matches "allow" followed by some spaces, new lines, and braces
Code: [Select]
"name"\s".+\n\s matches "name" and someones name, followed by some spaces and new lines
Code: [Select]
"group"\s"new"\n\}\n matches "group" and "new", followed by some spaces and new lines and the closing brace and then another newline

all put together:
Code: [Select]
"STEAM_0:(0|1):\d+"\s\n{\n\s"deny"\s\n\s{\n\s\}\n\s"allow"\s\n\s{\n\s\}\n\s"name"\s".+\n\s"group"\s".+"\n\}\n
Of course because of the genius of users.txt, the deny, allow, and name fields can be in any order. Hip hurray! (I'm sure there must be a good reason for this, and I'm curious what that reason is. It's just also pretty irritating.)

Just go ahead and re-order those three elements (total of six possible combinations) and you should be able to get them all.
« Last Edit: May 27, 2016, 04:40:27 AM by roastchicken »
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline Bryantdl7

  • Jr. Member
  • **
  • Posts: 86
  • Karma: -2
Re: Help with bulk deletion
« Reply #2 on: September 24, 2015, 07:02:25 AM »
Thank you so much! It worked perfectly! users.txt 407kb down to 41 kb!
+Rep



Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: Help with bulk deletion
« Reply #3 on: September 24, 2015, 09:54:54 AM »
Use notepad++'s replace feature. It accepts regex expressions and you can just replace it with nothing.

I really need to learn more about regex haha, looks powerful.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Help with bulk deletion
« Reply #4 on: September 24, 2015, 03:10:35 PM »
Yea I've never used it before, but it seemed like it would work for this. I just used an online regex tester that also had a regex cheatsheet. It was much easier than I expected.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with bulk deletion
« Reply #5 on: September 25, 2015, 08:10:44 AM »
RegEx is awesome and used in so many different coding/scripting languages for string manipulation it's incredible.
I too never learned even 1% of what it can do.
RoastChicken, though I'm sure we could all find one or two using Google, you should share your link that helped you.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Help with bulk deletion
« Reply #6 on: September 25, 2015, 10:31:54 PM »
The site I used was https://regex101.com/, but as you said there are tons of regex testers out there. I like  this site in particular because it explains what each character in your command does, so you can find mistakes more easily.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.