bat Поиск и удаление текста на одну строчку ниже найденного текста (второй вариант)
Windows
Просмотров: 827
Поиск текста "txt1" и удаление строчки с текстом "txt1" и строчке ниже.
$sSourceFile = 'C:\Мои проекты\0272\in866 2.txt'
$sString4Find = 'txt1'
$sPattern = ".*$sString4Find.*`r`n.*(?:`r`n|$)"
if([System.IO.File]::Exists($sSourceFile)) {
$sContent = Get-Content -Path $sSourceFile -Encoding UTF8 -Raw
if([Regex]::IsMatch($sContent, $sPattern)) {
[Regex]::Replace($sContent, $sPattern, '') | Set-Content -Path $sSourceFile -Encoding UTF8 -NoNewline
Write-Host "Found [$sString4Find] and replaced in content of source file [$sSourceFile]." -ForegroundColor Green
} else {
Write-Host "Not found [$sString4Find] in content of source file [$sSourceFile]." -ForegroundColor Red
}
} else {
Write-Host "Can't find source file [$sSourceFile]." -ForegroundColor Red
}
поиска текста txt1 и удаления строчки с текстом txt1 и строчки ниже.