我想从robocopy日志文件中删除%progress-value的所有行。这些行看起来像这样:
*EXTRA Datei 7.3 g test.pst
Neuer 7.3 g huge.PST
0.0%
0.0%
0.0%
0.1%
0.1%
0.1%
0.1%
99.8%
99.9%
99.9%
99.9%
99.9%
99.9%
100%
Neue Datei 7.5 g another.PST
0.0%
这次尝试我没有成功
FINDSTR.exe /V "%" LogFile.txt > LogFileWithoutPercentageLines.txt
因为这会减少太多的线条(在上面的示例中,整个行包含huge.PST
和another.PST
)
%-lines包括0.0%之前的两个空格和CR %-lines包括10.0%之前的一个空格和CR %-line在100.0%之前没有空格,在100%之后包含两个空格和CR。
我怎样才能摆脱这个无用的0.0%直到只有FINDSTR的100%行?
答案 0 :(得分:1)
在robocopy /?
中使用robocopy
with /NP
switch,cf 记录选项:
/NP :: No Progress - don't display percentage copied.
例如,robocopy "%_source%" "%_target%" /log:"%temp%\38610436.log" /NP
但是,下一个评论脚本显示了从现有杂草感染的日志文件中删除所有不需要的进度内容的可能方法(findstr
本身不会足以完成这项复杂的任务):
@ECHO OFF >NUL
SETLOCAL EnableExtensions DisableDelayedExpansion
set "_source=d:\bat\odds and ends\B" rem change to match your circumstances
set "_target=d:\bat\odds and ends\Bcopy" rem detto
set "_logFileRawData=%temp%\38610436.log" rem detto
set "_logFileCleaned=%temp%\38610436a.log" rem detto
rem /NP : No Progress - don’t display % copied
rem robocopy "%_source%" "%_target%" /log:"%temp%\38610436.log" /NP
robocopy "%_source%" "%_target%" /log:"%temp%\38610436.log"
>"%_logFileCleaned%" (
for /f "usebackq tokens=1,* delims=:" %%G in ( `findstr /N "^" "%_logFileRaw%"` ) do (
set "_line=%%H"
call :strip_Progress
SETLOCAL EnableDelayedExpansion
echo(!_line!
ENDLOCAL
)
)
ENDLOCAL
goto :eof
:strip_Progress
set "_zero=" rem zero percent indicator
set "_line=%_line%" rem remove all Carriage Return characters
rem after above command, _line with progress could be, excluding Square Brackets:
rem [New File 0 ZeroFile.ext100% ]
rem [New File 51808 TinyFile.txt 0% 100% ]
rem [Newer 1.1 m Mid_File.ext 0% 21% 42% 64% 85% 100% ]
rem [New File 162.1 m Big_File.ext 0.0% 0.6% 1.2% … 99.3% 99.9%100% ]
if "%_line%"=="" goto :eof
if "%_line:~-6%"=="100%% " call :removeProgress
goto :eof
:removeProgress
set "_line=%_line:~0,-6%" rem strip six trailing characters
if defined _zero goto :eof
rem as yet, zero percent indicator not set
:stripTrailingSpace
if "%_line:~-2%"==" " set "_line=%_line:~0,-1%" & goto :stripTrailingSpace
if "%_line:~-4%"==" 0%%" set "_zero=4" & set "_line=%_line%x%%"
if "%_line:~-6%"==" 0.0%%" set "_zero=6"
if "%_line:~-1%"=="%%" goto :removeProgress
goto :eof
更多资源(必读,不完整):
%G
,%H
等特殊页面)Command Line arguments (Parameters) >
,&
等特殊页面)Redirection %_line:~0,-6%
等)Extract part of a variable (substring) %%
加倍百分号)Escape Characters, Delimiters and Quotes