Home / Microsoft / Microsoft DOS / Doubt in cmd comands.
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: Doubt in cmd comands.  (Read 638 times)
roohi
Topic Starter
Beginner



Posts: 96


« on: June 10, 2009, 12:21:27 AM »

Hello every one :)

I have facing a problem while echo a list on command promt , and need the help .

I have a list:   LIST=abc:::123:::xyz
Now i want to print this list in a file as follows:
abc
123
xyz

Now i dont know how to do it , plz help me to slove this.

Thanks in advance.
IP logged
devcom
Apprentice



Thanked: 37
Posts: 521


« Reply #1 on: June 10, 2009, 05:25:58 AM »

Code: [Select]
REM SET LIST
set LIST=abc:::123:::xyz
REM CHANGE ::: TO "SPACE"
set LIST=%LIST::::= %

REM GET ALL TOKENS ON LIST
for %%a in (%LIST%) do echo %%a

pause
IP logged

Download: Choice.exe
billrich
Guest
« Reply #2 on: June 10, 2009, 05:43:40 AM »

C:\>type finalstr.bat
Code: [Select]
@echo off
set str=abc:::123:::xyz
echo."%str%"
set str=%str::= %
echo %str%

for /f "tokens=1,2,3,4 delims= " %%a in ("%str%") do ( set x=%%a & set y=%%b & s
et z=%%c)

echo.x:  %x%
echo.y:  %y%
echo.z:  %z%



echo  %x%  > savestr.txt
echo  %y%  >> savestr.txt
echo  %z%  >> savestr.txt

echo. The file with each string on separate line

Type savestr.txt

Output of finalstr.bat

C:\>finalstr.bat
Quote
"abc:::123:::xyz"
abc   123   xyz
x:  abc
y:  123
z:  xyz
 The file with each string on separate line
abc
123
xyz
C:\>
IP logged
roohi
Topic Starter
Beginner



Posts: 96


« Reply #3 on: June 12, 2009, 01:24:43 AM »

thanks, it helps me :)
IP logged
gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« Reply #4 on: June 12, 2009, 01:35:40 AM »

if you have gawk for windows(see my sig )
Code: [Select]
C:\test>set str=abc:::123:::xyz

C:\test>echo %str%|gawk -F":::" "$1=$1" OFS="\n"
abc
123
xyz

redirect to new file as needed.
IP logged

Pages: [1] - (Top) Print 
Home / Microsoft / Microsoft DOS / Doubt in cmd comands. « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.079 seconds with 21 queries.