Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOS batch command to read some info from text file

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)
like image 786
Ray Avatar asked Apr 02 '10 23:04

Ray


1 Answers

Here's a one line version:

for /f "tokens=2" %%i in ('findstr Revision: input.txt') do set revision=%%i
  1. findstr is used to filter the file. It will print "input.txt:Revision: 1234"
  2. Then the "tokens=2" means that we are interested in the second token, "1234". By default for breaks on white space.
like image 138
shf301 Avatar answered Nov 15 '22 07:11

shf301