Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8086

Профиль | Отправить PM | Цитировать


Добавлю и своё до кучи (на PowerShell):
Скрытый текст
Код: Выделить весь код
$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
}
Это сообщение посчитали полезным следующие участники:

Отправлено: 14:13, 16-08-2019 | #12