batch script - read line by line

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

    For those with spaces in the path, you are going to want something like this: n.b. It expands out to an absolute path, rather than relative, so if your running directory path has spaces in, these count too.

    set SOURCE=path\with spaces\to\my.log
    FOR /F "usebackq delims=" %%A IN ("%SOURCE%") DO (
        ECHO %%A
    )
    

    To explain:

    (path\with spaces\to\my.log)
    

    Will not parse, because spaces. If it becomes:

    ("path\with spaces\to\my.log")
    

    It will be handled as a string rather than a file path.

    "usebackq delims=" 
    

    See docs will allow the path to be used as a path (thanks to Stephan).

提交回复
热议问题