如何在批处理脚本中读取文件的最后两行 [英] How can I read the last 2 lines of a file in batch script

查看:106
本文介绍了如何在批处理脚本中读取文件的最后两行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java程序,它将新的构建信息附加到文件的最后两行中. 如何在批处理文件中读取它们?

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?

推荐答案

这将解决问题,其中someFile.txt是您要从中读取以下行的文件:

This will solve the problem, where someFile.txt is the file where you want to read the lines from:

for /f %%i in ('find /v /c "" ^< someFile.txt') do set /a lines=%%i
echo %lines%
set /a startLine=%lines% - 2
more /e +%startLine% someFile.txt > temp.txt
set vidx=0
for /F "tokens=*" %%A in (temp.txt) do (
    SET /A vidx=!vidx! + 1
    set localVar!vidx!=%%A
)
echo %localVar1%
echo %localVar2%
del temp.txt

这篇关于如何在批处理脚本中读取文件的最后两行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆