Solved

extract a part  of a value from a DOS variable

Posted on 2011-03-01
6
590 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 55

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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