1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| @echo off
setlocal enabledelayedexpansion
set "ScriptName=%~n0"
set "WorkPath=%cd%"
:ParseArgs
if "%~1"=="" goto Init
if "%~1"=="/?" goto Help
if "%~1"=="/s" (
set "Search=%~2"
shift /1
shift /1
goto ParseArgs
)
if "%~1"=="/p" (
set "WorkPath=%~2"
shift /1
shift /1
goto ParseArgs
)
:BadSyntax
echo.
for /f "delims=" %%a in ('net helpmsg 87') do echo [ %~1 ] %%a
echo.
exit /b 87
:Init
if not exist "%WorkPath%" (
call :UnknowError "%WorkPath%"
exit /b 87
)
if defined Search goto Exec
:UnknowError
if "%~1"=="" (
call :BadSyntax "/s"
) else (
call :BadSyntax "%~1"
)
echo.
call :Help
exit /b 87
:Exec
for /r "%WorkPath%" %%a in (*.log *.lst) do (
echo Fichier en cours: "%%~a".
rem Le fichier est parsé à la recherche de ora-^%^%Search^%^%
rem Les éléments trouvé sont placé dans "^%^%~dpatmp_purge_^%^%~nxa"
rem Le reste est placé dans "^%^%~dpatmp_^%^%~nxa"
(
(
for /f "usebackq delims=" %%b in (`type "%%~a"`) do (
echo %%b | find /i "ora-%Search%" >&3
echo %%b | find /i /v "ora-%Search%" >&4
)
) 4>>"%%~dpatmp_%%~nxa"
) 3>>"%%~dpatmp_purge_%%~nxa"
rem Le reste est déplacé vers le fichier originale.
move /y "%%~dpatmp_%%~nxa" "%%~a" 1>nul
rem Les éléments trouvé sont parsés afin de supprimer la chaîne "ora-"
for /f "usebackq delims=" %%b in (`type "%%~dpatmp_purge_%%~nxa"`) do (
set str=%%b
set str=!str:ora-%Search%=%Search%!
echo !str! >>"%%~dpapurge_%Search%_%%~nxa"
)
rem Le fichier temporaire contenant les éléments trouvé est supprimé
del /q "%%~dpatmp_purge_%%~nxa"
)
goto End
:Help
echo.
echo %ScriptName% /s ^<motif^> [/p ^<path^>]
echo %ScriptName% /?
echo.
echo /s ^<motif^> Définit le motif de recherche.
echo /p ^<path^> Définit le chemin d'accès de la recherche. Si le chemin n'est spécifié
echo la recherche s'effectue sur le répertoire courrant.
echo. /? Affiche cette aide.
echo.
:End
exit /b 0 |