我怎样才能读取批处理脚本中的文件的最后两行? [英] How can i read last 2 lines of a file in batch script

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

问题描述

我有一个java程序在文件的最后两行添加新的版本信息。如何在批处理文件中读取它们?

I have a java program which appends new builds information in 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天全站免登陆