Add to every end of line in Notepad++

I have a long text file

gallery-dl -g -i w4b027.txt >
gallery-dl -g -i a4b028.txt >
gallery-dl -g -i b4b029.txt >
gallery-dl -g -i c4b030.txt >
gallery-dl -g -i d4b031.txt >
gallery-dl -g -i w4b032.txt >
gallery-dl -g -i w4b033.txt >
gallery-dl -g -i w4b034.txt >
gallery-dl -g -i w4b035.txt >
gallery-dl -g -i w4b036.txt >
gallery-dl -g -i w4b037.txt >
gallery-dl -g -i w4b038.txt >
gallery-dl -g -i w4b039.txt >
gallery-dl -g -i w4b040.txt >

I want to make it

gallery-dl -g -i a4b027.txt > a4b027x.txt
gallery-dl -g -i b4b028.txt > b4b028x.txt
gallery-dl -g -i c4b029.txt > ...

the first text file to the second text file with suffix "x".


Solution 1:

  • Ctrl+H
  • Find what: ^.+\h(\S+)(\.txt) >\K
  • Replace with: $1x$2
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

^           # beginning of line
  .+          # 1 or more any character but newline
  \h          # horizontal space
  (\S+)       # group 1, 1 or more non-space character
  (\.txt)     # group 2, extension .txt
   >          # a space and > character
  \K          # forget all we have seen until this position

Replacement:

 $1         # a space and content of group 1 (filename)
x           # letter x
$2          # content of group 2 (extension)

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Solution 2:

You can hold alt to select the file names in block mode. Then copy and paste them to the desired location and then modify all rows at once.

It's easier to describe with a gif than with words:

Notepadd++ block mode copy and paste

Instead of using the mouse, you can also hold shift+alt and then use the arrow keys to select in block mode. You can also use the page up/down keys to quickly select whole columns in larger files.

Solution 3:

Another way to simplify repetitive tasks with Notepad++ is with the Macro feature.

The below steps will use keyboard keystrokes which the macro will repeat for you...

  1. Open the long text file and put the mouse cursor to the very beginning far left of the first line

    enter image description here

  2. Select Macro | Start Recording from the Notepad++ upper menu bar

    enter image description here

This is where you start the keyboard steps to complete the task for the first line

  1. Hold down on Ctrl and press the key 7 times

  2. Hold down on Ctrl+Shift and press the key 3 times

  3. Press Ctrl+C

  4. Press the End key 1 time

  5. Press Ctrl+V

  6. Hold down on Ctrl and press the key 2 times

  7. Press the X key 1 time

  8. Press the key 1 time

  9. Press the Home key 1 time

This is where you stop the keyboard steps that completed the task for the first line

  1. Select Macro | Stop Recording from the Notepad++ upper menu bar enter image description here

You now have the macro built so you can start it and play it to the end of the file to perform those actions until the last line and it'll take care of the repetition for you.

So just stay on the second line of your document after pressing the number 11 Home key and...

  1. Select Macro | Run a Macros Multi Times... from the Notepad++ upper menu bar

    enter image description here

  2. Check Run until the end of the file and then press Run

    enter image description here

Output Results

gallery-dl -g -i w4b027.txt > w4b027x.txt
gallery-dl -g -i a4b028.txt > a4b028x.txt
gallery-dl -g -i b4b029.txt > b4b029x.txt
gallery-dl -g -i c4b030.txt > c4b030x.txt
gallery-dl -g -i d4b031.txt > d4b031x.txt
gallery-dl -g -i w4b032.txt > w4b032x.txt
gallery-dl -g -i w4b033.txt > w4b033x.txt
gallery-dl -g -i w4b034.txt > w4b034x.txt
gallery-dl -g -i w4b035.txt > w4b035x.txt
gallery-dl -g -i w4b036.txt > w4b036x.txt
gallery-dl -g -i w4b037.txt > w4b037x.txt
gallery-dl -g -i w4b038.txt > w4b038x.txt
gallery-dl -g -i w4b039.txt > w4b039x.txt
gallery-dl -g -i w4b040.txt > w4b040x.txt

Supporting Resources

  • Notepad++ Macros Example

Solution 4:

Notepad++ search and replace:

Find what: gallery-dl -g -i (\w+).txt >
Replace with: gallery-dl -g -i \1.txt > \1x.txt

It will need to be modified if not all the lines terminate with a blank.

enter image description here