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-11 04:22
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] Batch Processing to Filter and Keep Specified Content in Text View 2,419 Replies 18
Original Poster Posted 2008-04-01 21:19 ·  中国 辽宁 沈阳 联通
中级用户
★★
Credits 234
Posts 119
Joined 2007-04-22 11:09
19-year member
UID 86077
Gender Male
Status Offline
Can batch processing achieve this?
Floor 2 Posted 2008-04-01 21:42 ·  中国 辽宁 沈阳 联通
中级用户
★★
Credits 234
Posts 119
Joined 2007-04-22 11:09
19-year member
UID 86077
Gender Male
Status Offline
Floor 3 Posted 2008-04-01 22:24 ·  中国 辽宁 沈阳 联通
中级用户
★★
Credits 234
Posts 119
Joined 2007-04-22 11:09
19-year member
UID 86077
Gender Male
Status Offline
Can someone help? Thank you very much
Floor 4 Posted 2008-04-01 22:44 ·  中国 江苏 常州 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
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
简单!简单!再简单!
Floor 5 Posted 2008-04-01 23:16 ·  中国 辽宁 沈阳 联通
中级用户
★★
Credits 234
Posts 119
Joined 2007-04-22 11:09
19-year member
UID 86077
Gender Male
Status Offline
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 ]
Floor 6 Posted 2008-04-01 23:19 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
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.
批处理之家新域名:www.bathome.net
Floor 7 Posted 2008-04-01 23:29 ·  中国 辽宁 沈阳 联通
中级用户
★★
Credits 234
Posts 119
Joined 2007-04-22 11:09
19-year member
UID 86077
Gender Male
Status Offline
Thank you very much. Can you help me write the comments for the just batch processing? It's better to be detailed. Thanks
Floor 8 Posted 2008-04-01 23:43 ·  中国 湖南 娄底 冷水江市 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
No good way, the file name cannot contain the # sign.
:

@echo off
for /f "delims=" %%i in ('findstr /i "\.asp" a.txt') do (
set "var=%%i"
setlocal enabledelayedexpansion
set var=!var:"=!
set var=!var:#=!
set var=!var:"=!
set var=!var:^>=!
set var=!var:^<=!
set var=!var:/==!
set var=!var:.asp=#!
call :loop
endlocal
)
start b.txt
exit
:loop
for /f "delims=#" %%a in ("!var!") do call :lis "%%a"
goto :eof
:lis
for /f "tokens=1* delims==" %%a in ("%~1") do (
if not "%%b"=="" (call :lis "%%b") else >>b.txt echo %%a.asp
)
goto :eof
致精致简!
Floor 9 Posted 2008-04-01 23:45 ·  中国 江苏 常州 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
@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"
简单!简单!再简单!
Floor 10 Posted 2008-04-01 23:47 ·  中国 江苏 常州 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Just sent it and then realized it was already there
简单!简单!再简单!
Floor 11 Posted 2008-04-02 08:11 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 471
Posts 207
Joined 2007-05-03 14:53
19-year member
UID 87369
Gender Male
Status Offline
Why not directly:
grep -oE "\w+\.asp" urfile.html
Floor 12 Posted 2008-04-02 13:32 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
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 ]
批处理之家新域名:www.bathome.net
Floor 13 Posted 2008-04-02 14:38 ·  中国 浙江 杭州 电信
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
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...
Floor 14 Posted 2008-04-02 14:47 ·  中国 北京 华为云
银牌会员
★★★
Credits 1,436
Posts 739
Joined 2007-10-11 17:44
18-year member
UID 99469
Gender Male
Status Offline
For handling this problem, VBS is simpler and more efficient. Why stick to one option only?
Floor 15 Posted 2008-04-02 14:51 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
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 ]
批处理之家新域名:www.bathome.net
Forum Jump: