问题
Could someone help me in this Batch script.
I need to run the below command svn info and to get certain details in a variable.
Path: .
Working Copy Root Path: C:\Users\jslevin\Desktop\SQL
URL: https://ofss220383.in.oracle.com:18080/svn/SVN_DEMO/branches/FCUBS_TEST/Soft/AM/SQL
Relative URL: ^/branches/FCUBS_TEST/Soft/AM/SQL
Repository Root: https://ofss220383.in.oracle.com:18080/svn/SVN_DEMO
Repository UUID: 866b0b85-a196-4771-a359-d37e344426b2
Revision: 47
Node Kind: directory
Schedule: normal
Last Changed Author: john.levin@oracle.com
Last Changed Rev: 47
Last Changed Date: 2016-04-11 18:01:56 +0530 (Mon, 11 Apr 2016)
Var1 = SVN_DEMO (This variable should hold the Repository Root: line and should get the Last word i.e., SVN_DEMO)
Var2 = FCUBS_TEST (Should grep URL: and hold the word after branches alone i.e., FCUBS_TEST)
And i'm creating some temp files in my script. at the end of script i need to find any available files and should delete it.
回答1:
probably even easier with unix-tools, but no big challenge with pure batch (kept it simple without optimizations):
@echo off
REM get the two important lines into variables:
for /f "tokens=*" %%a in ('find "Repository Root" file.txt') do set var1=%%a
for /f "tokens=*" %%a in ('find "Relative URL" file.txt') do set var2=%%a
:loop
REM var1 - remove from the beginning until (including) the first '/':
set var1=%var1:*/=%
REM if there is another '/' then do it again:
if "%var1%" neq "%var1:/=%" goto :loop
REM kind of "brute force", isn't it?
REM var2: remove from the beginning until (including) 'branches/':
set var2=%var2:*branches/=%
REM take the first token by '/' as delimiter:
for /f "delims=/" %%a in ("%var2%") do set var2=%%a
set var
来源:https://stackoverflow.com/questions/36744084/batch-script-to-store-certain-output-details-in-a-variable