How can I read the last 2 lines of a file in batch script

前端 未结 3 494
情话喂你
情话喂你 2021-01-18 22:40

I have a Java program that appends new builds information in the last two lines of a file. How can I read them in batch file?

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 23:32

    ::change the values bellow with a relevant ones.
    set "file=C:\some.file"
    set "last_lines=2"
    
    
    for /f %%a in ('findstr /R /N "^" "%file%" ^| find /C ":"') do @set lines=%%a
    set /a m=lines-last_line
    more +%m% "%file%"
    

    Directly from the command line:

    C:\>set "file=C:\some.file"
    C:\>set "last_lines=5"
    C:\>(for /f %a in ('findstr /R /N "^" "%file%" ^| find /C ":"') do @set lines=%a)&@set /a m=lines-last_lines&call more +%m% "%file%"
    

提交回复
热议问题