How do I merge 2 text files into one file?

让人想犯罪 __ 提交于 2019-12-11 15:22:23

问题


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
    


来源:https://stackoverflow.com/questions/52757447/how-do-i-merge-2-text-files-into-one-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!