Parse output line in batch mode

I have Kaspersky exit from scanning by calling avp.com in a batch program. I have this output in a variable called RES, the contents of this variable:

enter image description here

I need to parse this string to get the Total detected value , in the above example 0 . I tried with the operator for in batch mode but did not get the result as expected.

Note. Edited using @mbroshi annotator

set KAVDir="C:\Program Files (x86)\Kaspersky Lab\Kaspersky Endpoint Security 10 for Windows\avp.com"
for /f "tokens=3 delims= " %%i in ('%KAVDir% /i0 %1 ^| FINDSTR "Total detected"') 
do 
( 
SET RES=%%i 
ECHO %RES% 
)

The output text of the program avp.com:

2014-02-26 15:01:58 Scan_Objects$0697         starting   1%         
; --- Settings ---
; Action on detect:     Ask user
; Scan objects:         All objects
; Use iChecker:         Yes
; Use iSwift:           Yes
; Try disinfect:        Yes
; Try delete:           Yes
; Try delete container: No
; Exclude by mask:      No
; Include by mask:      No
; Objects to scan:      
;   "D:\Codigo\Git_Segmail\mail_filters\segmail20\server\service_node_helpers\antivirusscripts\eicar.com.txt"   Enable=Yes  Recursive=No
; ------------------
2014-02-26 15:01:58 D:\Codigo\Git_Segmail\mail_filters\segmail20\server\service_node_helpers\antivirusscripts\eicar.com.txt:Zone.Identifier ok
Progress 50%...
2014-02-26 15:01:58 D:\Codigo\Git_Segmail\mail_filters\segmail20\server\service_node_helpers\antivirusscripts\eicar.com.txt detected    EICAR-Test-File
Progress 50%...
2014-02-26 15:01:58 Scan_Objects$0697         running    50%        
2014-02-26 15:02:00 D:\Codigo\Git_Segmail\mail_filters\segmail20\server\service_node_helpers\antivirusscripts\eicar.com.txt was deleted
2014-02-26 15:02:00 Scan_Objects$0697         completed             
;  --- Statistics ---
;  Current time:    2014-02-26 15:02:00
; Time Start:           2014-02-26 15:01:58
; Time Finish:          2014-02-26 15:02:00
; Completion:           100%
; Processed objects:    2
; Total detected:       1
; Detected exact:       1
; Suspicions:           0
; Treats detected:      1
; Untreated:            0
; Disinfected:          0
; Quarantined:          0
; Deleted:              1
; Skipped:              0
; Archived:             0
; Packed:               0
; Password protected:   0
; Corrupted:            0
; Errors:               0
; Last object:          
;  ------------------

Any help would be helpful. Thanks

+4
source share
2 answers
@ECHO OFF
SETLOCAL
set KAVDir="C:\Program Files (x86)\Kaspersky Lab\Kaspersky Endpoint Security 10 for Windows\avp.com"
FOR /f "eol=#tokens=2delims=:" %%a IN ('%KAVDir% /i0 %1 ^|find "Total detected"') DO SET /a totdet=%%a
ECHO Total detected is %totdet%
GOTO :EOF

, findstr "Total detected" , "Total" ", FIND ( findstr /c:"Total detected"

+2

FINDSTR, :

set KAVDir="C:\Program Files (x86)\Kaspersky Lab\Kaspersky Endpoint Security 10 for Windows\avp.com"
for /f "eol=# tokens=4 delims= " %%i in (
    '%KAVDir% /i0 %1 ^| FINDSTR /C:"Total detected"'
) do (
    set RES=%%i
)

. Magoo, /C " " eol for , ;.

+2

Source: https://habr.com/ru/post/1529054/


All Articles