Search code examples
notepad++

How to increase a specific value by 1


I have a list of values

(1, 90, 1, 0);
(1, 29, 1, 0);
(1, 220, 1, 0);
(1, 218, 1, 0);
(1, 312, 1, 0);
(1, 13, 1, 0);

Using Notepad++ I want to create a copy of every one of these values and increase the first by one every time. For example the file should be

(1, 90, 1, 0);
(1, 29, 1, 0);
(1, 220, 1, 0);
(1, 218, 1, 0);
(1, 312, 1, 0);
(1, 13, 1, 0);
(2, 90, 1, 0);
(2, 29, 1, 0);
(2, 220, 1, 0);
(2, 218, 1, 0);
(2, 312, 1, 0);
(2, 13, 1, 0);
(3, 90, 1, 0);
(3, 29, 1, 0);
(3, 220, 1, 0);
(3, 218, 1, 0);
(3, 312, 1, 0);
(3, 13, 1, 0);

And so on, around 13,000 times

Is there a way to do this?


Solution

  • With Python you could try:

    filename = "yourFileName.txt"  # the file where you want to have the values
    n = 13_000  # number of times each should be printed, you suggested 13,000
    lists = [[1, 90, 1, 0],
             [1, 29, 1, 0],
             [1, 220, 1, 0],
             [1, 218, 1, 0],
             [1, 312, 1, 0],
             [1, 13, 1, 0]]
    
    with open(filename, "w") as file:
        for _ in range(n)
            for l in lists:
                file.write("({});\n".format(', '.join(str(x) for x in l)))
                l[0] += 1
    

    Make sure the file already exists, or else you'll get an error. (Edit: that is not true, files don't have to exist in append "a" or write "w" mode; thanks to @DarrylG)

    Also, I am assuming you want the brackets around your values as well as the semicolon, so they are also included in the file.

    So your file would look exactly like this:

    (1, 90, 1, 0);
    (1, 29, 1, 0);
    (1, 220, 1, 0);
    (1, 218, 1, 0);
    (1, 312, 1, 0);
    (1, 13, 1, 0);
    (2, 90, 1, 0);
    (2, 29, 1, 0);
    (2, 220, 1, 0);
    (2, 218, 1, 0);
    (2, 312, 1, 0);
    (2, 13, 1, 0);
    (3, 90, 1, 0);
    (3, 29, 1, 0);
    (3, 220, 1, 0);
    (3, 218, 1, 0);
    (3, 312, 1, 0);
    (3, 13, 1, 0);
    ...