[英]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.