• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 602
  • Last Modified:

extract a part of a value from a DOS variable

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
Aaron Shilo
Asked:
Aaron Shilo
1 Solution
 
Neil RussellTechnical Development LeadCommented:
An excellant guide to manipulating strings in a command shell is here.

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

0
 
Christopher McKayCommented:
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
 
OrenRozenCommented:
hi,

use the following command :

for /f "delims=:" %a in ('echo %ENV%') DO @echo %a
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
Bill PrewCommented:
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
 
Christopher McKayCommented:
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
 
Aaron ShiloAuthor Commented:
thanks
a clear and simple solution.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now