Powershell 合并2个大文本文件

Powershell 合并2个大文本文件,powershell,command-line,command,Powershell,Command Line,Command,我试图在Windows10中合并两个大的文本文件(每个200mb),但我常用的方法命令Window>>Copy*.txt combine.txt似乎不起作用。输出的文件只有一个文件的大小,所以我假设该方法不适用于大文件。是否有其他方法可以轻松执行此操作?如果目标文件不存在或已包含内容,则需要首先发出New Item命令。如果您知道它不存在或为空,可以跳过下面的那一行 New-Item -ItemType file ".\combined_files.txt" –force Get-Conten

我试图在Windows10中合并两个大的文本文件(每个200mb),但我常用的方法命令Window>>Copy*.txt combine.txt似乎不起作用。输出的文件只有一个文件的大小,所以我假设该方法不适用于大文件。是否有其他方法可以轻松执行此操作?

如果目标文件不存在或已包含内容,则需要首先发出New Item命令。如果您知道它不存在或为空,可以跳过下面的那一行

New-Item -ItemType file ".\combined_files.txt" –force

Get-Content .\file?.txt | Add-Content .\combined_files.txt

如果目标文件不存在或已包含内容,则需要首先发出newitem命令。如果您知道它不存在或为空,可以跳过下面的那一行

New-Item -ItemType file ".\combined_files.txt" –force

Get-Content .\file?.txt | Add-Content .\combined_files.txt

您可以简单地附加它

Get-content file1.txt | out-file c:\combined.txt -append
Get-content file2.txt | out-file c:\combined.txt -append
一种更快的方法是.net ReadLines

[System.io.file]::readlines("c:\file1.txt") | out-file c:\combined.txt -append
[System.io.file]::readlines("c:\file2.txt") | out-file c:\combined.txt -append

您可以简单地附加它

Get-content file1.txt | out-file c:\combined.txt -append
Get-content file2.txt | out-file c:\combined.txt -append
一种更快的方法是.net ReadLines

[System.io.file]::readlines("c:\file1.txt") | out-file c:\combined.txt -append
[System.io.file]::readlines("c:\file2.txt") | out-file c:\combined.txt -append

是否会添加内容
做您想做的事
gci*.txt |%{Add Content$\ucombine.txt-encoding Byte}
或类似的
COPY*.txt Combine.txt
应该可以工作。您确定这两个.txt文件都在目录中吗?您也可以尝试
COPY file1.txt+file2.txt Combine.txt
。是否
添加内容
执行您想要执行的操作
gci*.txt |%{Add Content$\ucombine.txt-encoding Byte}
或类似的
COPY*.txt Combine.txt
应该可以工作。您确定这两个.txt文件都在目录中吗?您也可以尝试
复制file1.txt+file2.txt Combine.txt