windows - win batch regexp search and replace -
i have set of info this
7859 10000:00 7859 10000:00 (xfer#1, to-check=1033/1035)
32768 000:17 22174479 10000:00 (xfer#2, to-check=1032/1035)
they read file , passed line line method within batch script want in method extract only
7859
22174479
from lines, whatever after "\d+:\d\d\s+", follows numbers need , "\d\d.*"
is possible using batch script regular look , search , replace? tried , read bunch of articles not find solution in , want add together numbers
thank you
edit based on andrei's comment david ruhmann's answer, andrei wants token 2 positions before (xfer#, not 3rd token beginning.
do note batch not best language utilize regex! cmd processes input 1 line @ time, whereas regex allows multi-line processing.
it sounds need perform token grab lines. assuming more finish regex line looks [\d+\s+\d+:\d\d\s+]+\(xfer#\d+, to-check=\d+/\d+\).
this allows know there constant delimiters in line. : colons, , \s+ whitespace. there matter of using anchors determine token position.
extract 3rd token delimited single line whitespace line.
for /f "tokens=3" %%a in ("line") echo %%a extract sec token delimited single line whitespace sec token delimited colons line.
for /f "tokens=2 delims=:" %%a in ("line") ( /f "tokens=2" %%b in ("%%a") echo %%b ) update
extract sec token before lastly colon.
@echo off setlocal enableextensions enabledelayedexpansion set "line=32768 004:47 2686976 2200:03 11707819 10000:01 (xfer#5264, to-check=1020/6975)" set "last=" /f "delims=" %%a in ('echo("%line::="^&echo("%"') ( /f "tokens=2" %%b in ("%%a") ( if defined set "last=!this!" set "this=%%b" ) ) echo %last% endlocal pause >nul limitations
lines containing odd number of double quotation marks" cause script crash. 1 method prevent strip out quotations before loop set line=%line:"=%. windows batch-file
No comments:
Post a Comment