Solved

extract a part  of a value from a DOS variable

Posted on 2011-03-01
6
549 Views
Last Modified: 2012-05-11
hi all

i have an ENV variable with a value  " machinename:abc "

i need to extract the " abc " from the VAR only.

source : MYVAR = machinename:abc
i need to extract : abc

this value will be ECHOed to a txt file.

this needs to be done in DOS, i cant use VB or any other kind of scripting but dos commands.

0
Comment
Question by:Aaron Shilo
6 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 35009518
An excellant guide to manipulating strings in a command shell is here.

http://www.dostips.com/DtTipsStringManipulation.php

0
 
LVL 22

Expert Comment

by:Bartender_1
ID: 35009534
Do you not have an environment variable called %computername% that you could use instead?
If you absolutely must use this variable, you could try this in a batch file:

for /f "tokens=2 delims =:" %%i in ("%myvar%") do echo %i


Hope this helps!

:o)

Bartender_1
0
 
LVL 3

Expert Comment

by:OrenRozen
ID: 35009546
hi,

use the following command :

for /f "delims=:" %a in ('echo %ENV%') DO @echo %a
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 51

Expert Comment

by:Bill Prew
ID: 35009554
Try this:

set MyVar=machinename:abc
for /F "tokens=2 delims=:" %%A in ("%MyVar%") do set MyRest=%%A
REM now you can use %MyRest% as needed, for example:
echo %MyRest%>>c:\temp\log.txt

Open in new window

~bp
0
 
LVL 22

Accepted Solution

by:
Bartender_1 earned 500 total points
ID: 35009557
Sorry, this in a batch file:
for /f "tokens=2 delims=:" %%i in ("%myvar%") do echo %%i

Open in new window

this if you want to run from a command prompt:
 
for /f "tokens=2 delims=:" %i in ("%myvar%") do echo %i

Open in new window

0
 
LVL 15

Author Closing Comment

by:Aaron Shilo
ID: 35009971
thanks
a clear and simple solution.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now