我正在使用 powershell 读取 TXT 并对其进行一些逻辑处理。TXT 以非常特定的格式设置,但我关心的唯一行以 6 或 4 开头。问题是我无法弄清楚如何检查下一行。我从
$files = Get-ChildItem $source *.*
$file = Get-Content $files
然后我检查每一行
foreach ($line in $file) {
if ($line.StartsWith("6")) {
Write-Host "This line starts with 6"
} elseif ($line.StartsWith("4")) {
Write-Host "This line starts with 4"
} elseif (($line.StartsWith("4")) -and (NEXT LINE STARTS WITH 4)) {
Write-Host "This line starts with 4 and the next line starts with 4"
} else {
Write-Host "This line does not start with 6 or 4"
}
}
$line + 1
我已经尝试过像or$line[x + 1]
甚至是这样的事情,$file[x + 1]
但它们并没有产生我想要的结果,因为它们会读入一行,然后读入下一行。谁能告诉我如何检查下一个 $line 是否以 4 开头?