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-08-04 09:08
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Help me take a look at how to use FOR to extract the content I need View 863 Replies 12
Original Poster Posted 2007-04-23 23:02 ·  中国 重庆 沙坪坝区 电信
中级用户
★★
金牌会员
Credits 315
Posts 152
Joined 2007-01-25 23:55
19-year member
UID 77669
Gender Male
Status Offline
Floor 2 Posted 2007-04-23 23:13 ·  中国 重庆 沙坪坝区 电信
中级用户
★★
金牌会员
Credits 315
Posts 152
Joined 2007-01-25 23:55
19-year member
UID 77669
Gender Male
Status Offline
for /f "tokens=2 delims=)" %1 in (2.txt) do @echo %1 >>23.txt
pause
Why can't I extract it~》??
Floor 3 Posted 2007-04-23 23:51 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
% parameters can only use a-z, A-Z
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
fengzi +2 2007-04-24 05:38
Floor 4 Posted 2007-04-24 00:54 ·  中国 浙江 杭州 联通
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Floor 5 Posted 2007-04-24 02:46 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
According to the OP's list, this works:
@echo off
for /f "tokens=2 delims=)" %%i in (2.txt) do echo %%~ni>>23.txt
pause
Floor 6 Posted 2007-04-24 03:48 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 302
Posts 138
Joined 2007-03-29 02:33
19-year member
UID 83224
Gender Male
Status Offline
for /f "tokens=1,* delims=)" %%a in (1.txt) do call :need %%bRead the content after ")" on each line of 1.txt into %%b and pass it to :need
:need
for /f "tokens=1 delims=." %%c in ("%1") do echo %%c>2.txtIn :need, use "%1" to call %%b and output the content before "." to 2.txt

[ Last edited by lililulula on 2007-4-23 at 03:26 PM ]
Floor 7 Posted 2007-04-24 04:03 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by lililulula at 2007-4-23 14:48:
for /f "tokens=1,* delims=)" %%a in (1.txt) do set need=%%b Take all content after the first ")" in all content of 1.txt, and assign it to the variable need
for /f "tokens=1 delims=." %%c in ("%need%") do echo %%c>2.txt Take all content in the need variable up to "." and output it to 2.txt
pause

The poster above should test it himself, the final result only outputs the last piece of data
Floor 8 Posted 2007-04-24 04:15 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 302
Posts 138
Joined 2007-03-29 02:33
19-year member
UID 83224
Gender Male
Status Offline
Reply to zh159, I noticed that myself earlier too, and I've already corrected it now, but after trying it, your script seems to be the same as what I had before, it can only export the last line - -, same with wudixin96's too, sweat.

[ Last edited by lililulula on 2007-4-23 at 03:23 PM ]
Floor 9 Posted 2007-04-24 04:22 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
The key is in %%~ni>>23.txt
Floor 10 Posted 2007-04-24 04:24 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 302
Posts 138
Joined 2007-03-29 02:33
19-year member
UID 83224
Gender Male
Status Offline
Yeah, that's right~~~ I was careless
Floor 11 Posted 2007-04-24 05:18 ·  中国 广东 广州 联通
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
Heh, the formats are all different...
Some take up two characters, some only one...
So of course the ones below won't work.
Unless you first do one replacement...

Or

@echo off

for /f "tokens=1,2,3,4,5 delims=)),, " %%a in (1.txt) do (
echo -------------------------------------------
echo %%a
echo %%b
echo %%c
echo %%d
echo %%e
echo -------------------------------------------
)
pause

Choose the part you need yourself based on the results...
知,不觉多。不知,乃求知
Floor 12 Posted 2007-04-24 05:36 ·  中国 重庆 沙坪坝区 电信
中级用户
★★
金牌会员
Credits 315
Posts 152
Joined 2007-01-25 23:55
19-year member
UID 77669
Gender Male
Status Offline
Originally posted by zh159 at 2007-4-23 10:51 AM:
%参数只能用a-z,A-Z

Thanks, actually right after I made the post I changed %1 to something else. Then it ran smoothly..
Didn't expect everyone to be so enthusiastic, with so many replies after that, thanks.
for /f "tokens=2 delims=)" %q in (2.txt) do @echo %q >>23.txt
pause
I still haven't had time to try the ones from the other friends above.
Floor 13 Posted 2007-04-24 12:45 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Save the content the OP wants to process as ok.txt, and the generated new file will be new.txt. The code is as follows:

@echo off&setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=1* delims=))" %%_ in (ok.txt) do (
set str=%%`
set str=!str:.jpg=!
>>new.txt echo\!str!
)
start new.txt


To (3F)zh159:
The parameters of the for command are not limited to only a-z or A-Z characters. As long as they are visible characters in the ASCII table, they can be used as parameters for the for command. But because some special symbols (such as & ^ | * %1 %2 etc.) have special meanings in batch files, those characters are excluded. For example, in the example above.
Forum Jump: