How do I merge 2 text files into one file?

2019-08-28 21:46发布

问题:

Okay so, I want to merge 2 text files :

File 1 :

Firstline
ABCD
Thirdline

Fifthine

File 2 :

Firstline

Thirdline
EFGH
Fifthline

Expected output :

Firstline
ABCD
Thirdline
EFGH
Fifthline

I can't use copy filea+fileb filec with cmd because it just copy and paste one to another and merge it into one file.

回答1:

Try the following procedure with notepad++:

  1. Go to file1 and add some data that cannot be found on the lines (for example @@@@@) at the beggining of each line with following regex replace: search (regex): ^ Replace by: @@@@@. After that, first file should look like this:

    @@@@@Firstline
    @@@@@ABCD
    @@@@@Thirdline
    @@@@@
    @@@@@Fifthine
    
  2. Go to second file and select (as columns) all data. You can do this placing at the beggining of the file and the ALT+SHIFT+(END, PAGEUP)

  3. Control+C for copy
  4. Go to first file, place at the beggining and paste with Control+V. The first file now should look like this:

    Firstline@@@@@Firstline
    @@@@@ABCD
    Thirdline@@@@@Thirdline
    EFGH@@@@@
    Fifthline@@@@@Fifthine
    
  5. Do a search and replace: Search (regex): ^@@@@@|@@@@@[^\n\r]* Replace: (nothing). The first file will be:

    Firstline
    ABCD
    Thirdline
    EFGH
    Fifthline