notepad++ how to add increase number every end line?

how to add increase number every end line ?

study
fly
run
swim
learning
todo
no

to become

study20978
fly20979
run20980
swim20981
learning20982
todo20983
no20984
2

2 Answers

I am Notepad++ user but I would use free AWK tool for this because it is lean and effective.

AWK solution (just download awk.exe and run the following command line)

awk "BEGIN { c = 20978 } { print $0 c++ }" input.txt > output.txt

Result:

study20978
fly20979
run20980
swim20981
learning20982
todo20983
no20984

Downloading:

you do not even need to install the tool, just download and unpack binaries.zip and EXE is located in gawk-3.1.6-1-bin.zip\bin\awk.exe.

What the instructions do:

  • BEGIN { c = 20978 } we initialized c to 20978. BEGIN section runs only once.
  • section { print $0 c++ } runs once for each line: we print that line (it is stored in $0) and the value of our counter c (which we immediately increase: c++)

Making it reusable:

If you would like to keep the source code for future use, put it to file numbering.awk with some nicer formatting:

BEGIN { c = 20978 }
{ print $0 c++ }

And use modified command line referring to that source file:

awk -f numbering.awk input.txt > output.txt

You can save this command into numbering.bat file so you won't need to rememeber it.

Additional explanation:

For your information, less cryptic form of the source would say:

# this section runs once at the beginning
BEGIN { c = 20978 } # initialization of the counter "c"
# this section runs once for each line
{ print $0 c; # print original line followed by value of counter "c" c = c + 1; # assign value of calculation "c + 1" into "c"
} 
3
  1. Add some spaces to the last time so that the line becomes the longest.

    enter image description here

  2. Hold Alt+Shift then hit Up Arrows to select an area up to the top of the text.

    enter image description here

  3. Keep holding Alt+Shift then hit Right Arrows to adjust the area so that the cursors are at the end of the lines.

    enter image description here

  4. Hit Alt+C to invoke the Column Editor to add sequence numbers.

    enter image description here

    enter image description here

  5. Hit Ctrl+H to replace the regular expression \ +([0-9]+)$ with $1

    enter image description here

    enter image description here

    Done!

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like