Solved

extract a part  of a value from a DOS variable

Posted on 2011-03-01
6
588 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Christopher McKay
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 54

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:
Christopher McKay 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Suggested Courses

739 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