batch script - read line by line

前端 未结 4 2019
醉话见心
醉话见心 2020-11-29 02:48

I have a log file which I need to read in, line by line and pipe the line to a next loop.

Firstly I grep the logfile for the \"main\" word (like \"error\") in a sep

4条回答
  •  北海茫月
    2020-11-29 03:30

    The "call" solution has some problems.

    It fails with many different contents, as the parameters of a CALL are parsed twice by the parser.
    These lines will produce more or less strange problems

    one
    two%222
    three & 333
    four=444
    five"555"555"
    six"&666
    seven!777^!
    the next line is empty
    
    the end
    

    Therefore you shouldn't use the value of %%a with a call, better move it to a variable and then call a function with only the name of the variable.

    @echo off
    SETLOCAL DisableDelayedExpansion
    FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ t.txt"`) do (
        set "myVar=%%a"
        call :processLine myVar
    )
    goto :eof
    
    :processLine
    SETLOCAL EnableDelayedExpansion
    set "line=!%1!"
    set "line=!line:*:=!"
    echo(!line!
    ENDLOCAL
    goto :eof
    

提交回复
热议问题