Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm aware that this is something people can easily program, but I'm not familiar with those things, so I was hoping there was an easier solution.

I've edited a large database of questions, including sorting, and ended up getting all the question ID's mixed up.

I'm trying to do this in Notepad++, but any other suggestions are welcome. I'm wondering if there's a way to search for a string (ex. "Question[any number]") and replace the numbers with first 1, then 2, et.c.

For clarification, this is how one question looks like:

TriviaBot_Questions[3]['Question'][63] = "Acronyms: What does WTT stand for?";  
TriviaBot_Questions[3]['Answers'][63] = {"Want To Trade"};  
TriviaBot_Questions[3]['Category'][63] = 7;  
TriviaBot_Questions[3]['Points'][63] = 1;
TriviaBot_Questions[3]['Hints'][63] = {};  

and the next question, as is now, is not followed by 64. It might be 245 or 1029, and regardless of which number it is, I want it replaced with "previous number + 1", basically.

share|improve this question

Well, it's easy enough with Emacs, but Emacs can be somewhat difficult to learn.

You can get it here: It is entirely free.

Make a backup of the file before going on, just in case, because it can be annoying to undo everything, and it never hurts to have a backup.

Here is how to do what you want, keystroke by keystroke. For reference, C means control and a dash means it has to be pressed simultaneously (e.g. control+x) while a space means you let go of what you had before. So C-x C-f means you press control+x and then control+f.

Open Emacs and open the file you have. If there is no file/edit...etc bar, you can open a file via C-x C-f (control+x followed by control+f) and entering the file path.

Then press C-x (, which is control+x followed by shift+9. This starts recording your keystrokes, which you can repeat later.

Now press C-s and type "Questions", followed by C-f twice and C-backspace. Now press f3. The number should be replaced by a 0. If you want multiple lines to have the same number, copy the number you just got with C-space followed by C-b and then M-w (alt+w).

With the number copied, you can use C-s again, pressing it twice to go to the next instance of "Questions". Here press C-f twice again followed by C-backspace but now type C-y to paste the number you copied. Repeat this as necessary to go through all the numbers in one question. Each time you repeat this action within that single question, type M-y after it.

Once you are done with the first question, and all the numbers are replaced with 0, you can now just finish recording the macro. Enter C-x ) (control-x followed by shift-0, just like before).

If, at any point, you make a mistake and what to cancel and restart, C-g cancels and C-_ (control + shift + -) undoes.

Now enter C-u 0 C-x e.

If it works, you can save the changes by typing C-x C-s.

What this does is create a keyboard macro to replace the number, execute it repeatedly with a counter (created by f3) incremented each time.

If you manage to make this work (I did, on your example), consider looking into learning how to use Emacs--there is a very nice tutorial that can be accessed when you open Emacs. It takes a bit of effort to learn, but it is worth it.

share|improve this answer
Thanks, I'll look into this. – user37610 May 19 '10 at 5:16

I am not aware of a tool that can do this, but you may find it better to either write your code like

x = 0;
Questions[3][++x] = 'New Question';
Questions[3][  x] = '------------';
Questions[3][  x] = 'A: Answer, B: Answer, C: Answer';
Questions[3][++x] = 'New Question';
Questions[3][  x] = '------------';
Questions[3][  x] = 'A: Answer, B: Answer, C: Answer';

Or a better solution would be to read from a text file or database, that way the questions are not tied to the compiled application.

Although if you want to solve the immediate problem at hand, I would put that questions file into Excel and do Text->Columns using the characters [ and ] as delimiters. Then sort.

share|improve this answer
The problem is not to sort them. I rearranged them into categories, which is why the Question ID's are not in order. The current order is correct, I just want to change the numbers. – user37610 May 19 '10 at 5:16
@Ciremo, then import to into Excel and do Text->Columns. Put a column with the numbers 1 to x identifying the row numbers (I am assuming it is column Z) Then write a macro for the IDs, something like =5*INT(Z1/5) for the ID column you want to replace. Drag it down. – May 19 '10 at 6:32
Also what might be easier is doing 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 down the list and then dragging that as a range. Excel should infer that you want to increment 1 every 5 steps. – May 19 '10 at 6:34

You must log in to answer this question.