这似乎太简单了,我很不好意思问。
我有一个文件,它的行数未知,但至少有20行。我总是希望将第4-6行移到第1-3行。
所以这个:
A
B
C
D
E
F
G
H变成这样:
D
E
F
A
B
C
G
H发布于 2020-03-21 11:16:47
$path = "C:\xxxx"
$pathnew = $path + "\new"
If(!(test-path $pathnew))
{
New-Item -ItemType Directory -Force -Path $pathnew
}
[System.Collections.ArrayList]$Files = @(Get-ChildItem $path -Filter *.json |
Where-Object {$_.PSIsContainer -eq $false} |
Select-Object FullName,Name)
foreach ($File in $Files) {
[System.Collections.ArrayList]$File_Contents = @(Get-Content $File.FullName)
$FN = $File.FullName
$OutPutFile = $pathnew + "\" + $File.Name
$txt = Get-Content $FN
$txt2 = Get-Content $FN | Measure-Object -Line
$txtLess3 = $txt2.Lines-3
$txt[6..12],"`"submission`": {",$txt[1..3]
," `"performanceYear`": 2019},"
,$txt[13..$txtLess3] | Out-File $OutPutFile
}发布于 2020-03-20 11:10:12
$Lines = 'A'..'H'
$Lines[3..5],$Lines[0..2],$Lines[6..99]或
$Lines[3,4,5,0,1,2,6,7,8,9]有关详细信息,请参阅:关于数组
https://stackoverflow.com/questions/60772541
复制相似问题