|
tomorrower
初级用户
 
积分 28
发帖 10
注册 2006-9-19
状态 离线
|
『楼 主』:
FOR循环中如何取文件中一行用|分割的多个值?
使用 LLM 解释/回答一下
有一个文本a.txt
435241|阳新|8区
435250|白沙|8区
****
怎么能够取到"|"分割的各个值?
There is a text a.txt
435241|Yangxin|District 8
435250|BaiSha|District 8
****
How to get the values separated by "|"?
|
|
2006-9-27 03:14 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
for /f "tokens=1,2,3 delims=|" %%i in (t.txt) do (...)
对于 /f "tokens=1,2,3 delims=|" %%i in (t.txt) do (...)
|
|
2006-9-27 03:20 |
|
|
tomorrower
初级用户
 
积分 28
发帖 10
注册 2006-9-19
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
谢谢你的回复
%%i 指的是第几个值?第一个还是第二个还是第三个?
Thank you for your reply.
What does %%i refer to, the first value, the second value, or the third value?
|
|
2006-9-27 04:35 |
|
|
9527
银牌会员
     努力做坏人
积分 1185
发帖 438
注册 2006-8-28 来自 北京
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
%%i 第一个
%%j 第二个
%%k 第三个
%%i The first one
%%j The second one
%%k The third one
|

我今后在论坛的目标就是做个超级坏人!!! |
|
2006-9-27 04:37 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
楼主先 for /? 看看
The landlord first, take a look at /?
|
|
2006-9-27 08:05 |
|
|
tomorrower
初级用户
 
积分 28
发帖 10
注册 2006-9-19
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by pip at 2006-9-27 04:37:
%%i 第一个
%%j 第二个
%%k 第三个
%%i ,%%j ,%%k 中i j k变量是随便的吗?随便的吗?还是确定顺序的?
我是菜鸟,虚心求助
Originally posted by pip at 2006-9-27 04:37:
%%i first
%%j second
%%k third
Are the variables i, j, k in %%i, %%j, %%k arbitrary? Are they arbitrary? Or are they in a fixed order?
I'm a newbie, asking for help humbly
|
|
2006-9-27 08:47 |
|
|
tomorrower
初级用户
 
积分 28
发帖 10
注册 2006-9-19
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
我写的在这里,但是执行总是失败:
for /f "tokens=1,2,3 delims=|" %%i in (txip.txt)
do ( echo 'update dzhd_t_txfjxx set v_ip=%%k where c_jgbh=%%i and c_txdm=%%j ;')
txip.txt的内容为:
31001402|07|10.138.9.165
31001402|05|10.238.60.81
31001402|06|10.138.9.164
31002001|05|10.138.9.37
31002001|06|10.138.9.38
31002801|01|10.138.13.10
31000903|01|10.138.20.68
31000903|03|10.138.20.74
错误信息为:
E:\ftp>sql.bat
命令语法不正确。
E:\ftp>for /f "tokens=1,2,3 delims=|" %i in (txip.txt)
I wrote it here, but execution always fails:
for /f "tokens=1,2,3 delims=|" %%i in (txip.txt)
do ( echo 'update dzhd_t_txfjxx set v_ip=%%k where c_jgbh=%%i and c_txdm=%%j ;')
The content of txip.txt is:
31001402|07|10.138.9.165
31001402|05|10.238.60.81
31001402|06|10.138.9.164
31002001|05|10.138.9.37
31002001|06|10.138.9.38
31002801|01|10.138.13.10
31000903|01|10.138.20.68
31000903|03|10.138.20.74
The error message is:
E:\ftp>sql.bat
The syntax of the command is incorrect.
E:\ftp>for /f "tokens=1,2,3 delims=|" %i in (txip.txt)
|
|
2006-9-27 08:58 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
%%i, %%j, %%k是一个次序问题; 如果初始变量定义为%%a, 那么排序将会是%%a, %%b, %%c, %%d...; 同样如果初始变量为%%0, 排序就是%%0, %%1, %%2...
这和FOR语句提取到的字符或字符串的基数有关, 每提取到一个字符或字符串就赋给下一个变量. 依此类推.
当然也有个数限制, 如果是字母定义的变量他们的数量不能超过26个(a-z).
用阿拉伯数字定义变量最多不能超过10个(0-9).
%%i, %%j, %%k are an order issue; if the initial variable is defined as %%a, then the sorting will be %%a, %%b, %%c, %%d...; similarly, if the initial variable is %%0, the sorting is %%0, %%1, %%2...
This is related to the base of the characters or strings extracted by the FOR statement. Each time a character or string is extracted, it is assigned to the next variable. And so on.
Of course, there are also quantity limits. If the variables are defined by letters, their number cannot exceed 26 (a-z).
The maximum number of variables defined by Arabic numerals cannot exceed 10 (0-9).
|
|
2006-9-27 09:07 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by pengfei at 2006-9-27 09:07:
当然也有个数限制, 如果是字母定义的变量他们的数量不能超过26个(a-z).
个数有限制的说法是正确的,但是字母变量的个数不能超过26个就不准了,因为for语句中的字母变量是要区分大小写的,所以字母变量的个数应该不能超过52个。
Originally posted by pengfei at 2006-9-27 09:07:
There are of course also number limits. If it is a variable defined by letters, their number cannot exceed 26 (a-z).
The statement that there are number limits is correct, but the claim that the number of letter variables cannot exceed 26 is incorrect because the letter variables in the for statement are case-sensitive, so the number of letter variables should not exceed 52.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-27 10:00 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
是的, 那么作为52个变量的赋值规律是, 先从小写赋值完成再赋给大写吗?
帮助中也提到过一行指定最多26个字符, 而提到的不能同时使用52个以上, 由于没有深究也就没有提出来.
Last edited by pengfei on 2006-9-27 at 10:17 ]
Yes, then the assignment rule for 52 variables is that the lowercase is assigned first and then assigned to the uppercase?
The help also mentioned that a line specifies a maximum of 26 characters, and the mention of not being able to use more than 52 at the same time, since I didn't study it deeply, I didn't mention it.
Last edited by pengfei on 2006-9-27 at 10:17 ]
|
|
2006-9-27 10:10 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by pengfei at 2006-9-27 10:10:
是的, 那么作为52个变量的赋值规律是, 先从小写赋值完成再赋给大写吗?
帮助中也提到过一行指定最多26个字符, 而提到的不能同时使用52个以上, 由䠮..
这个问题倒没深入地想过,推测是这样的:如果一开始就用了小写来定变量名,那么,同一层上的for后面的变量最多应该只能到z,如果是大写的话,最多就只能到Z,也就是说,变量名的大小写应该是从一而终的,不可混用的,否则,帮助里也就不会有 一行指定最多26个字符, 而提到的不能同时使用52个以上 这个提法了。仅是推测而已,有了解的请再深入地分析一下吧。
Originally posted by pengfei at 2006-9-27 10:10:
Yes, then the assignment pattern for 52 variables is to first complete the assignment in lowercase and then assign to uppercase?
The help also mentioned that a line specifies a maximum of 26 characters, and it mentioned that more than 52 cannot be used at the same time, by 䠮..
This question hasn't been deeply thought about. It is speculated like this: If you start using lowercase letters to define variable names, then the variables after for on the same level should at most only go to z. If it is uppercase, it can at most only go to Z. That is to say, the case of variable names should be consistent from start to finish, and cannot be mixed. Otherwise, there wouldn't be the statement in the help that a line specifies a maximum of 26 characters, and it mentioned that more than 52 cannot be used at the same time. It's just a speculation. Those who understand, please analyze it more deeply.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-27 10:28 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by namejm at 2006-9-27 10:28:
这个问题倒没深入地想过,推测是这样的:如果一开始就用了小写来定变量名,那么,同一层上的for后面的变量最多应该只能到z,如果是大写皠...
我想是这样的吧, 一个循环中使用字母做变量不能为52个以上, 变量名只能为单一字母分大小写, 这样系统能够正常处理的字母变量就不能大于52个.
如果加上数字, 在全局中变量最多可以使用62个, 而FOR提取文本行赋于变量数不能大于26个(a-z)或(A-Z).
Originally posted by namejm at 2006-9-27 10:28:
This problem hasn't been deeply thought about. It is speculated like this: if lowercase letters are used to define variable names from the beginning, then the maximum number of variables after for on the same level should be up to z. If it is uppercase...
I think it is like this. The number of letters used as variables in a loop cannot be more than 52. Variable names can only be single letters, case-sensitive. So the number of letter variables that the system can handle normally cannot be more than 52.
If numbers are added, the maximum number of variables that can be used globally is 62, and the number of variables assigned by FOR to extract text lines cannot be more than 26 (a-z) or (A-Z).
|
|
2006-9-27 11:08 |
|
|
tomorrower
初级用户
 
积分 28
发帖 10
注册 2006-9-19
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
大家帮帮忙看看我到底错在哪里啊?
for /f "tokens=2,3* delims=|" %%i in (txip1.txt)
do ( echo 'update dzhd_t_txfjxx set v_ip=%%k where c_jgbh=%%i and c_txdm=%%j ;') >a.sql
提示为"E:\ftp>rem for /f "tokens=1,2,3 delims=|" %0 in (txip1.txt)
命令语法不正确。
E:\ftp>for /f "tokens=2,3* delims=|" %i in (txip1.txt)"
Everyone, help me see where I made a mistake.
for /f "tokens=2,3* delims=|" %%i in (txip1.txt)
do ( echo 'update dzhd_t_txfjxx set v_ip=%%k where c_jgbh=%%i and c_txdm=%%j ;') >a.sql
The prompt is "E:\ftp>rem for /f "tokens=1,2,3 delims=|" %0 in (txip1.txt)
The command syntax is incorrect.
E:\ftp>for /f "tokens=2,3* delims=|" %i in (txip1.txt)
|
|
2006-9-27 20:24 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
echo 那行的 () 打错了, >a.sql 应该和 ECHO 在一起的。
The parentheses in that line were mistyped. `>a.sql` should be together with ECHO.
|
|
2006-9-27 20:58 |
|
|
piziliu2004
中级用户
   过度热情
积分 321
发帖 139
注册 2006-3-21
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
刚才帮你写的代码。 呵呵。有兴趣看看
Function splitfile(strFile)
Const ForReading = 1,ForWriting=2
Dim i, retstring
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(strFile, ForReading, False)
Do While theFile.AtEndOfStream <> True
retstring=Split(theFile.ReadLine,"|",-1,1)
For i=0 to UBound(retstring)
wscript.echo retstring(i)
Next
loop
theFile.Close
End Function
The code you just wrote. Hehe. Interested to take a look
Function splitfile(strFile)
Const ForReading = 1,ForWriting=2
Dim i, retstring
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(strFile, ForReading, False)
Do While theFile.AtEndOfStream <> True
retstring=Split(theFile.ReadLine,"|",-1,1)
For i=0 to UBound(retstring)
wscript.echo retstring(i)
Next
loop
theFile.Close
End Function
|

知识在于不断积累 |
|
2006-9-28 04:20 |
|