Merge 2 text files into one, same lines

  1. Add space characters to the end of the first line of file1 until it is longer than the longest line in file1.

  2. Do a column mode selection of the entire contents of file 2. Do this by holding the ALT key down while dragging the mouse across the file. As you drag you should see a rectangular area of the screen selected. It may be easiest to start the selection before the first character in the first line of file2. Could also do a column mode selection with just the keyboard. Hold the ALT and Shift keys down while moving the cursor with the arrow keys.

  3. Copy the selected text. (Control-C or menu => Edit => Copy or context menu => copy.)

  4. Paste after the spaces added to file1.

  5. Remove unnecessary spaces.

If the existing spaces in files1 and file2 are important you might use a regular expression to alter every line in file2 to have some character or character sequence that does not occur in either file before selecting its contents. For example, find ^ and replace with !!. Then you can use another regular expression to remove only the spaces added by the paste. For example, replace _*!! (space, asterisk, exclamation-mark, exclamation-mark) with _ (space; note that spaces would show incorrectly in these two strings, so they are shown as underscores _ for clarity).

See also the Editing => Column mode editing section of the Notepad++ help pages.

Leave a Comment