Батник:
читать дальше »
Код:
@echo off
setlocal
set "list=1.ini 2.ini"
set "search=val_farm_zone"
for %%i in (%list%) do call:parse "%%i"
for /f "tokens=2 delims==" %%i in ('set file_') do echo program.exe %%i
goto:eof
:parse
set file=%~1
for /f "tokens=*" %%i in (%file%) do (
1>nul 2>&1 (
echo %%i| findstr "^\[.*\]$" && set "section=%%i"
if "%%i"=="name = %search%" call:set
)
)
goto:eof
:set
set /a cnt+=1
set "file_%cnt%=%file% %section%"
Powershell:
читать дальше »
Код:
$list = '1.ini', '2.ini'
$value = 'val_farm_zone'
$files = @{}
foreach ($file in $list) {
switch -regex (( gc $file )) {
"\[.*\]" { $sec = $_ }
"^name = $value" { $files."$file" += $sec }
}
}
$files.keys | % {
$f = $_
$s = $files."$_"
write-host "& program.exe $f $s"
}
ЗЫ. А внешняя программа только удаляет определенные секции? Просто это можно сделать прямо из скрипта Powershell.