Reputation: 141
I want to copy the content of my text file test1.txt
in the line 52 of my second text file test2.txt
.
To copy I use the following commands:
$a=Get-Content "C:\Users\Administrator\Destop\test1.txt"
"$a"|Out-File "C:\Users\Administrator\Desktop\test2.txt" -Append
But how can I define a specific line? And how to overwrite when there is something?
Upvotes: 1
Views: 543
Reputation: 58981
The 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"
Upvotes: 2