0

Consider out.txt file has the following format:

Display Variable;

    ID    NAME       value
===*==========*================
201  Variavle     07Dec2014

Display Variable12;

ID    NAME          value
===*==========*================
201  Variavle12     08Dec2014

Display Variable123;

ID    NAME       value
===*==========*================
201  Variavle123     09Dec2014    

In batch file we need to search for Variable, Variable12 and Variable123 and return each string in column value to batch file to environment variables with the names from column NAME like

SET Variavle=09Dec2014
SET Variavle12=08Dec2014
SET Variavle123=09Dec2014

Please help me to get it done.

1
  • Hi John, what have you tried? It could be interesting to see what kind of code are you using and where exactly are you having problems. Commented Dec 7, 2014 at 18:46

3 Answers 3

1
@echo off

for /f "tokens=2,3 delims= " %%A in ('FINDSTR /i /r  /c:"Variavle.* " out.txt') do (
    set "%%A=%%B"
)

set Variavle
Sign up to request clarification or add additional context in comments.

1 Comment

Following code helped me get the var=value@echo off for /f "tokens=* " %%A in ('FINDSTR /i /r /c:"Variable " D:\test.txt') do ( SET _test=%%A SET Variable=%_test:~20,5% ECHO %Variable% )
0

Following code helped me to find the answer

SET Variavle=09Dec2014

SET Variavle12=08Dec2014 SET Variavle123=09Dec2014

@echo off   
for /f "tokens=* " %%A in ('FINDSTR /i /r  /c:"Variable     " D:\test.txt') do (    
SET _test=%%A
SET Variable=%_test:~20,5%
ECHO %Variable%
)    

... ...

Let me know if any changes !

Thanx for the help.

Comments

0

@npocmaka

"dev.bat"

@echo off
for /f "tokens=* " %%A in ('FINDSTR /i /r /c:"nBegin_fcst_dt " D:\test.txt') do (
SET _test=Variavle 20142 SET nBegin_fcst_dt=%_test:~13,5% ECHO:%nBegin_fcst_dt% ) "D:\test.txt" ID NAME value ============================= 201 Variavle 20142

I just ran the above script like "test.bat"

I got some weird output.

Expected output 20142

when i ran the script, i got the actual output at third time

First time: Nothing

Second time:~13,5 Third time:20142

D:>dev.bat

D:>dev.bat ~13,5 D:>dev.bat 20142

Comments

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.