Powershell Copy in 某行

Powershell Copy in certain line

我想将我的文本文件test1.txt的内容复制到我的第二个文本文件test2.txt的第52行。 要复制,我使用以下命令:

$a=Get-Content "C:\Users\Administrator\Destop\test1.txt"
"$a"|Out-File "C:\Users\Administrator\Desktop\test2.txt" -Append

但是如何定义特定的行呢? 有东西的时候怎么覆盖?

Get-Content cmdlet basically returns a object array thus you can use some array range operators:

$a = Get-Content "C:\Users\Administrator\Destop\test1.txt"
$b = Get-Content "C:\Users\Administrator\Destop\test2.txt"

@($b[0 .. 51], $a) | out-File "C:\Users\Administrator\Desktop\test2.txt"