中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-04 10:06
48,038 topics / 350,123 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » Help me take a look at how to use FOR to extract the content I need
Printable Version  864 / 12
Floor1 fengzi Posted 2007-04-23 23:02
中级用户 Posts 152 Credits 315
Floor2 fengzi Posted 2007-04-23 23:13
中级用户 Posts 152 Credits 315
for /f "tokens=2 delims=)" %1 in (2.txt) do @echo %1 >>23.txt
pause
Why can't I extract it~》??
Floor3 zh159 Posted 2007-04-23 23:51
金牌会员 Posts 1,467 Credits 3,687
% parameters can only use a-z, A-Z
Floor4 wudixin96 Posted 2007-04-24 00:54
银牌会员 Posts 931 Credits 1,928
Floor5 zh159 Posted 2007-04-24 02:46
金牌会员 Posts 1,467 Credits 3,687
According to the OP's list, this works:
Floor6 lililulula Posted 2007-04-24 03:48
中级用户 Posts 138 Credits 302
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 ]
Floor7 zh159 Posted 2007-04-24 04:03
金牌会员 Posts 1,467 Credits 3,687
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
Floor8 lililulula Posted 2007-04-24 04:15
中级用户 Posts 138 Credits 302
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 ]
Floor9 zh159 Posted 2007-04-24 04:22
金牌会员 Posts 1,467 Credits 3,687
The key is in %%~ni>>23.txt
Floor10 lililulula Posted 2007-04-24 04:24
中级用户 Posts 138 Credits 302
Yeah, that's right~~~ I was careless
Floor11 flyinspace Posted 2007-04-24 05:18
银牌会员 Posts 517 Credits 1,206
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...
Floor12 fengzi Posted 2007-04-24 05:36
中级用户 Posts 152 Credits 315
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.
Floor13 lxmxn Posted 2007-04-24 12:45
版主 Posts 4,938 Credits 11,386
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:


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.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023