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 07:06
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to get multiple values separated by | in a line of a file in a FOR loop? View 4,020 Replies 20
Floor 16 Posted 2006-09-28 05:12 ·  中国 浙江 杭州 电信
初级用户
Credits 28
Posts 10
Joined 2006-09-19 13:29
19-year member
UID 63072
Gender Male
Status Offline
Originally posted by NaturalJ0 at 2006-9-27 20:58:
The parentheses in that line were typed wrong. `>a.sql` should be together with ECHO.



This is also incorrect:
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>sql.bat
The command syntax is incorrect.

E:\ftp>for /f "tokens=2,3* delims=|" %i in (txip1.txt)
Floor 17 Posted 2006-09-28 05:13 ·  中国 浙江 杭州 电信
初级用户
Credits 28
Posts 10
Joined 2006-09-19 13:29
19-year member
UID 63072
Gender Male
Status Offline
Originally posted by piziliu2004 at 2006-9-28 04:20:
The code I just wrote for you. Hehe. Interested to take a look
Function splitfile(strFile)
Const ForReading = 1,ForWriting=2
Dim i, retstring
Set fso = CreateObject("Scripting.FileSystemObject" ...


Thank you for your enthusiastic help!
But my level is really not good, can you explain it?
Floor 18 Posted 2006-09-28 05:42 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Originally posted by tomorrower at 2006-9-28 05:12:

This is also incorrect:
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:
...


The problem with the code on the first floor is indeed that the redirection is not within the execution range of the FOR statement.

And the modified code here is also incorrect. It is recommended to look at for /?!

The code is modified as follows:
@echo off
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
)
pause

Just found out after posting the thread that the original intention of the landlord is not that the sentence >a.sql is to overwrite. The landlord may want to append >>a.sql

[ Last edited by pengfei on 2006-9-28 at 05:48 ]
Floor 19 Posted 2006-10-16 00:41 ·  中国 广东 东莞 电信
中级用户
★★
Credits 282
Posts 130
Joined 2006-09-20 22:25
19-year member
UID 63201
From 广东
Status Offline
Learning
~~~~好好学习
天天向上~~~~
Floor 20 Posted 2006-10-16 17:08 ·  中国 河南 安阳 电信
初级用户
Credits 39
Posts 15
Joined 2006-10-14 07:42
19-year member
UID 65719
Status Offline
Your tokens shouldn't be 2, 3. Otherwise, change %i.
Floor 21 Posted 2007-07-05 09:52 ·  中国 浙江 嘉兴 海宁市 电信
中级用户
★★
Credits 360
Posts 216
Joined 2007-05-29 17:41
19-year member
UID 89677
Gender Male
Status Offline
Hehe, if the token is more than 62, like 100, then what should be done?
Forum Jump: