China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 19:24
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved] Variable usage and parsing issues in batch processing View 1,943 Replies 5
Original Poster Posted 2011-01-07 11:45 ·  中国 陕西 西安 电信
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
All are written in the rem

@echo off
Setlocal
set _project_a1=a
set _project_a2=a,b
set _project_a3=b,c
set _project_a4=c,a
set _all_a=
set _all_b=
set _all_c=
rem Want to implement _all_a to record all projects containing a, _all_b to record all projects containing b, _all_c to record all projects containing c,
rem _all_a=_project_a1,_project_a2,_project_a4
rem _all_b=_project_a2,_project_a3
rem _all_c=_project_a3,_project_a4

rem Don't know how to implement
for /f %%i in ('set _project_') do call :Function1 %%i
echo _all_a=%_all_a%
echo _all_b=%_all_b%
echo _all_c=%_all_c%
endlocal
@goto :eof

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Function1
echo %%1=%1
@goto :eof


[ Last edited by danjiang on 2011-1-8 at 11:53 ]
Floor 2 Posted 2011-01-07 14:52 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
```
@echo off&setlocal enabledelayedexpansion
set _project_a1=a
set _project_a2=a,b
set _project_a3=b,c
set _project_a4=c,a
for /l %%a in (1,1,4) do for %%b in (!_project_a%%a!) do if defined _all_%%b (set _all_%%b=!_all_%%b!,_project_a%%a) else set _all_%%b=_project_a%%a
set _project_
set _all_
pause
or:
@echo off&setlocal enabledelayedexpansion
set _project_a1=a
set _project_a2=a,b
set _project_a3=b,c
set _project_a4=c,a
for /f "tokens=1* delims==" %%a in ('set _project_') do for %%c in (%%b) do if defined _all_%%c (set _all_%%c=!_all_%%c!,%%a) else set _all_%%c=%%a
set _project_
set _all_
pause

[ Last edited by Hanyeguxing on 2011-1-7 at 15:11 ]
```
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
danjiang +1 2011-01-08 10:48
Floor 3 Posted 2011-01-08 10:25 ·  中国 陕西 西安 电信
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
Floor 4 Posted 2011-01-08 10:30 ·  中国 陕西 西安 电信
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
Thanks, it's what I need, the second method is better. Can I continue to ask, can the following be simplified:

_all_a=_project_a1,_project_a2,_project_a4
_all_b=_project_a2,_project_a3
_all_c=_project_a3,_project_a4

to

_all_a=a1,a2,a4
_all_b=a2,a3
_all_c=a3,a4
Floor 5 Posted 2011-01-08 10:51 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
```@echo off
set _project_a1=a
set _project_a2=a,b
set _project_a3=b,c
set _project_a4=c,a
for /f "tokens=2* delims==_" %%a in ('set _project_') do for %%c in (%%b) do if defined _all_%%c (call set _all_%%c=%%_all_%%c%%,%%a) else set _all_%%c=%%a
set _project_
set _all_
pause
```
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
danjiang +1 2011-01-08 11:02
Floor 6 Posted 2011-01-08 11:02 ·  中国 陕西 西安 电信
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
Thank you so much!!!
Forum Jump: