2016-07-27 79 views
0

我想從我的robocopy日誌文件中去除所有具有%progress-value的行。該線路是這樣的:如何使用FINDSTR從robocopy日誌文件中去除%行?

  *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.PSTanother.PST整條生產線)

%-lines包含0.0%之前的兩個空格和一個CR。
%-lines包含10.0%之前的一個空格和一個CR。
%-line在100.0%之前不包含空格,但在100%之後包含兩個空格和一個CR。

我該如何擺脫這個毫無用處的0.0%,直到只有FINDSTR的100%行?

回答

1

使用robocopy with /NP switch,CF 記錄選項robocopy /?

/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 

更多資源(必讀的,不完全):

+0

非常感謝您對你的解決方案僅用於記錄:在這種情況下執行沒有百分比進度的robocopy不是一個選項,因爲用戶必須在屏幕上看到像7.5 GB * .pst這樣的大文件的進度。沒有辦法使用/ NP僅用於日誌,AFAIK。 – PeterCo

相關問題