Concatenate text files with Windows command line, dropping leading lines

前端 未结 12 833
心在旅途
心在旅途 2020-11-30 18:03

I need to concatenate some relatively large text files, and would prefer to do this via the command line. Unfortunately I only have Windows, and cannot install new software.

相关标签:
12条回答
  • 2020-11-30 18:46

    In powershell:

    Get-Content file1.txt | Out-File out.txt
    Get-Content file2.txt | Select-Object -Skip 1 | Out-File -Append out.txt
    
    0 讨论(0)
  • 2020-11-30 18:53

    Here's how to do this:

    (type file1.txt && more +1 file2.txt) > out.txt
    
    0 讨论(0)
  • 2020-11-30 18:54

    I don't have enough reputation points to comment on the recommendation to use *.csv >> ConcatenatedFile.csv, but I can add a warning:

    If you create ConcatenatedFile.csv file in the same directory that you are using for concatenation it will be added to itself.

    0 讨论(0)
  • 2020-11-30 19:01
    more +2 file2.txt > temp
    type temp file1.txt > out.txt
    

    or you can use copy. See copy /? for more.

    copy /b temp+file1.txt  out.txt
    
    0 讨论(0)
  • 2020-11-30 19:04

    I use this, and it works well for me:

    TYPE \\Server\Share\Folder\*.csv >> C:\Folder\ConcatenatedFile.csv

    Of course, before every run, you have to DELETE C:\Folder\ConcatenatedFile.csv

    The only issue is that if all files have headers, then it will be repeated in all files.

    0 讨论(0)
  • 2020-11-30 19:04

    This takes Test.txt with headers and appends Test1.txt and Test2.txt and writes results to Testresult.txt file after stripping headers from second and third files respectively:

    type C:\Test.txt > C:\Testresult.txt && more +1 C:\Test1.txt >> C:\Testresult.txt && more +1 C:\Test2.txt >> C:\Testresult.txt
    
    0 讨论(0)
提交回复
热议问题