繁体   English   中英

在某些行中复制Powershell

[英]Powershell Copy in certain line

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

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

但是,如何定义特定行? 以及在有东西时如何覆盖?

Get-Content cmdlet基本上返回一个对象数组,因此您可以使用一些数组范围运算符

$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"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM