中国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-11 03:33
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » [Closed] Batch Processing to Filter and Keep Specified Content in Text
Printable Version  2,414 / 18
Floor1 w1314ich Posted 2008-04-01 21:19
中级用户 Posts 119 Credits 234
Can batch processing achieve this?
Floor2 w1314ich Posted 2008-04-01 21:42
中级用户 Posts 119 Credits 234
Floor3 w1314ich Posted 2008-04-01 22:24
中级用户 Posts 119 Credits 234
Can someone help? Thank you very much
Floor4 terse Posted 2008-04-01 22:44
银牌会员 Posts 946 Credits 2,404
Using batch processing is terrible and difficult because of special characters

@echo off
for /f "tokens=* delims=:" %%a in ('findstr /n "\.asp" a.txt') do (
set var=%%a
setlocal enabledelayedexpansion
set var=!var:*:=!
set var=!var:*"=!
set var=!var:"= !
if not "!var!"=="" for /f "delims= " %%i in ("!var!") do if "%%~xi"==".asp" (>>bak.txt echo %%i)
endlocal
)
pause
Floor5 w1314ich Posted 2008-04-01 23:16
中级用户 Posts 119 Credits 234
gywmen.asp
index.asp
xhjs1.asp
hyzj1.asp
xhxx1.asp
hydt1.asp
jlhz1.asp
pxtd1.asp
zcfg1.asp
wscy.asp
wlzwhjj.asp
http://www.ec315.cn/onlinets.asp
wsdj.asp
qikan.asp
admin/vote/vote_js.asp
zddh.asp
lxwm.asp
wscy.asp
jlhz1.asp
http://www.sh-ec.org.cn/yqlj.asp

[ Last edited by w1314ich on 2008-4-1 at 11:22 PM ]
Floor6 bat-zw Posted 2008-04-01 23:19
金牌会员 Posts 1,276 Credits 3,105
I spent about an hour, and I can only say it's too difficult. Many things can't be extracted. The main thing is the situation is too complicated.
Floor7 w1314ich Posted 2008-04-01 23:29
中级用户 Posts 119 Credits 234
Thank you very much. Can you help me write the comments for the just batch processing? It's better to be detailed. Thanks
Floor8 26933062 Posted 2008-04-01 23:43
银牌会员 Posts 879 Credits 2,268
No good way, the file name cannot contain the # sign.
:
Floor9 terse Posted 2008-04-01 23:45
银牌会员 Posts 946 Credits 2,404
@echo off
for /f "tokens=* delims=:" %%a in ('findstr /n "\.asp" a.txt') do (
set var=%%a
setlocal enabledelayedexpansion
set var=!var:*:=!
set var=!var:*"=!
set var=!var:"= !
set var=!var:?= !
set var=!var:^>= !
set var=!var:^<= !
if not "!var!"=="" for /f "tokens=1* delims= " %%i in ("!var!") do if "%%~xi"==".asp" (>>bak.txt echo %%i) else call :lp "%%j"
endlocal
)
pause
goto :eof
:lp
for /f "tokens=1* delims= " %%i in ("%~1") do if "%%~xi"==".asp" (>>bak.txt echo %%i&goto :eof) else call :lp "%%j"
Floor10 terse Posted 2008-04-01 23:47
银牌会员 Posts 946 Credits 2,404
Just sent it and then realized it was already there
Floor11 ThinKing Posted 2008-04-02 08:11
中级用户 Posts 207 Credits 471
Why not directly:
Floor12 bat-zw Posted 2008-04-02 13:32
金牌会员 Posts 1,276 Credits 3,105
Originally posted by w1314ich at 2008-4-1 23:29:
Thank you very much. Can you write the comments for the just batch processing for me? It's better to be detailed. Thanks

@echo off
for /f "tokens=* delims=:" %%a in ('findstr /n "\.asp" a.txt') do (
set var=%%a
setlocal enabledelayedexpansion
set var=!var:*:=!
set var=!var:*"=!
set var=!var:"= !
set var=!var:?= !
set var=!var:^>= !
set var=!var:^<= !
if not "!var!"=="" for /f "tokens=1* delims= " %%i in ("!var!") do if "%%~xi"==".asp"

(>>bak.txt echo %%i) else call :lp "%%j"
endlocal
)
pause
goto :eof
:lp
for /f "tokens=1* delims= " %%i in ("%~1") do if "%%~xi"==".asp" (>>bak.txt echo %%i&goto

:eof) else call :lp "%%j"

 At the request of the poster and to the best of my ability, the following is the explanation for TERSE's wonderful code (please forgive and give advice if there are errors and deficiencies):
 The batch processing first uses the first for loop to enable variable delay, uses ":" as the delimiter to replace special characters (:"") in each segment of the string in a.txt with nothing, and replaces special characters (?><) with space " " (this is to prepare for the delims= in the subsequent for loop);
 Then, it performs an if judgment on the replaced string to see if it is empty. If it is not empty, it enters the second for loop, and again uses if to judge the first string %%i with " " as the delimiter to see if there is a file name with.asp as the suffix name (here, variable expansion %%~xi is used to expand variable %%i to the file extension). If there is, it adds this string (%%i) to the input back.txt. If not (else), it jumps to the next for loop with the label lp, and passes the substring "%%j variable" after %%i to the next for loop (note that enclosing %%j in double quotes here is to enable the next for loop to correctly identify the variable %%j with spaces);
 In the last for loop, it is actually constantly repeating the work of the previous for loop until the last string with.asp as the suffix is taken out and added to back.txt. It's just that here, %%~1 is used to remove the double quotes of the variable and expand the variable %%~1 (the variable "%%j" with double quotes passed from the previous for loop).
 Another very difficult process to explain, sweat......
[ Last edited by zw19750516 on 2008-4-2 at 01:41 PM ]
Floor13 bjsh Posted 2008-04-02 14:38
银牌会员 Posts 621 Credits 2,000
If it were me, I would use Python to parse it. It's still quite simple, and of course, the efficiency is higher than batch processing...
Floor14 abcd Posted 2008-04-02 14:47
银牌会员 Posts 739 Credits 1,436
For handling this problem, VBS is simpler and more efficient. Why stick to one option only?
Floor15 bat-zw Posted 2008-04-02 14:51
金牌会员 Posts 1,276 Credits 3,105
I disagree with the opinions of abcd. We are dealing with this problem to achieve improvement, and for no other reason.

[ Last edited by zw19750516 on 2008-4-2 at 02:52 PM ]
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023