batch script - read line by line

前端 未结 4 2058
醉话见心
醉话见心 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:13

    Try this:

    @echo off
    for /f "tokens=*" %%a in (input.txt) do (
      echo line=%%a
    )
    pause
    

    because of the tokens=* everything is captured into %a

    edit: to reply to your comment, you would have to do that this way:

    @echo off
    for /f "tokens=*" %%a in (input.txt) do call :processline %%a
    
    pause
    goto :eof
    
    :processline
    echo line=%*
    
    goto :eof
    
    :eof
    

    Because of the spaces, you can't use %1, because that would only contain the part until the first space. And because the line contains quotes, you can also not use :processline "%%a" in combination with %~1. So you need to use %* which gets %1 %2 %3 ..., so the whole line.

提交回复
热议问题