Solved

extract a part  of a value from a DOS variable

Posted on 2011-03-01
6
583 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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