0

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: [email protected]
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.

2
  • 2
    where is the batch script, you need help with? Commented Apr 20, 2016 at 12:53
  • @Stephan, I use awk, grep to achieve my target in shell but wondering how to use findstr and grep in batch to achieve my result. Any idea Appreciated. Commented Apr 20, 2016 at 17:33

1 Answer 1

0

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 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Stephen. Your Idea made me to modify and get the results what i was expecting. So here is my Code........................................... .for /f "tokens=4 delims=//" %%i in ('findstr /ilc:"Repository Root" "svninfo"') do ( set var1=%%i ) for /f "tokens=3 delims=^/" %%j in ('findstr /ilc:"Relative URL" "svninfo"') do ( set var2=%%j ) echo %var1% 1>&2 echo %var2% 1>&2 exit 1
be careful: tokens= will give false results, if your path has another depth. That's why I didn't use tokens. and just took "the last from repository" and "next to 'branches' ".
@Stephen, The character length i need to fetch will always be stable. So i guess it will not be trouble for me.. Will it misbehave in this case also ?. By the way Thank U very much for your support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.