DOS批处理命令来读取文本文件中的一些信息 [英] DOS batch command to read some info from text file
本文介绍了DOS批处理命令来读取文本文件中的一些信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过使用Windows命令行读取文本文件的一些信息,并将其保存到一个变量,就像集信息= 1234
下面是TXT文件的内容,其实我只是需要的版本号,以及它的位置始终是相同的5号线,并从塔11到15.这是1234的样品,我想知道是有没有办法将其保存在DOS命令行中的变量。
非常感谢!
svninfo.txt:
路径。
网址:https://www.abc.com
存储库根:https://www.abc.com/svn
版本库的UUID:12345678-8b61-fa43-97dc-123456789
修订:1234
节点种类:目录
附表:正常
最后的修改作者:ABC
上次更改修订:1234
上次更改日期:2010-04-01 18点19分54秒-0700(周四,01 2010年4月)
解决方案
下面是一个行版本:
FOR / F令牌= 2%% i的('FINDSTR修订:input.txt的')不要设置修订= %%我
- FINDSTR用来过滤该文件。这将打印input.txt中:修订:1234
- 那么令牌= 2的意思是我们感兴趣的第二令牌,1234。默认情况下对空格符。
I am trying to read some info from a text file by using windows command line, and save it to a variable just like "set info =1234"
Below is the content of the txt file, actually I just need the revision number, and the location of it is always the same line 5, and from column 11 to 15. In the sample it's 1234, and I am wondering is there a way to save it to a variable in Dos command line.
Thanks a lot!
svninfo.txt:
Path: .
URL: https://www.abc.com
Repository Root: https://www.abc.com/svn
Repository UUID: 12345678-8b61-fa43-97dc-123456789
Revision: 1234
Node Kind: directory
Schedule: normal
Last Changed Author: abc
Last Changed Rev: 1234
Last Changed Date: 2010-04-01 18:19:54 -0700 (Thu, 01 Apr 2010)
解决方案
Here's a one line version:
for /f "tokens=2" %%i in ('findstr Revision: input.txt') do set revision=%%i
- findstr is used to filter the file. It will print "input.txt:Revision: 1234"
- Then the "tokens=2" means that we are interested in the second token, "1234". By default for breaks on white space.
这篇关于DOS批处理命令来读取文本文件中的一些信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文