【发布时间】:2019-05-15 15:42:53
【问题描述】:
我有一组主要的价值观和一个子集
主套装:Group1,Group2,Group3
子集:Group1_Sub1,Group1_Sub2,Group2_Sub1,Group3_Sub1,Group3_Sub2
Group1 ->Group1_Sub1 and Group1_Sub2
Group2 ->Group2_Sub1
Group3 ->Group3_Sub1,Group3_Sub2
对于每个主列表,我只想循环遍历其对应的子组列表并显示输出。
目前我正在使用以下代码
for %%s in (
Group1,Group2,Group3
) do (
echo set Main Group %%s >> Log.txt
for %%i in (
Group1_Sub1,Group1_Sub2,Group2_Sub1,Group3_Sub1,Group3_Sub2
) do (
echo Main Group is %%s and its sub group is %%i >>Log.txt
)
)
上面的代码会给我输出:
set Main Group Group1
Main Grpup is Group1 and its sub group is Group1_Sub1
Main Grpup is Group1 and its sub group is Group1_Sub2
Main Grpup is Group1 and its sub group is Group2_Sub1
Main Grpup is Group1 and its sub group is Group3_Sub1
Main Grpup is Group1 and its sub group is Group3_Sub2
set Main Group Group2
Main Grpup is Group2 and its sub group is Group1_Sub1
Main Grpup is Group2 and its sub group is Group1_Sub2
Main Grpup is Group2 and its sub group is Group2_Sub1
Main Grpup is Group2 and its sub group is Group3_Sub1
Main Grpup is Group2 and its sub group is Group3_Sub2
set Main Group Group3
Main Grpup is Group3 and its sub group is Group1_Sub1
Main Grpup is Group3 and its sub group is Group1_Sub2
Main Grpup is Group3 and its sub group is Group2_Sub1
Main Grpup is Group3 and its sub group is Group3_Sub1
Main Grpup is Group3 and its sub group is Group3_Sub2
我想限制他们只通过下面的相应列表
set Main Group Group1
Main Grpup is Group1 and its sub group is Group1_Sub1
Main Grpup is Group1 and its sub group is Group1_Sub2
set Main Group Group2
Main Grpup is Group2 and its sub group is Group2_Sub1
set Main Group Group3
Main Grpup is Group3 and its sub group is Group3_Sub1
Main Grpup is Group3 and its sub group is Group3_Sub2
我怎样才能做到这一点?
【问题讨论】:
-
IIUR 使用
for /f解析具有不同长度变量名称的集合的输出,集合将输出具有给定前缀的 all 变量和他们的内容。 -
您是否知道您的代码不访问任何变量,而只是通过连接字符串来生成输出?
标签: batch-file cmd batch-processing