中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-12 00:34
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [已结] 文本片断提取 查看 2,140 回复 25
16 发表于 2009-04-26 11:17 ·  中国 湖北 黄石 电信
中级用户
★★
积分 330
发帖 244
注册 2006-04-14 14:07
20年会员
UID 53823
性别 男
来自 湖北
状态 离线
保存为s.bat
s ab 查找 --AB--
s ab pb 查找 --AB-- --PB--
s PB Ab c4 查找- --PB-- --AB-- --C4--
@echo off&setlocal enabledelayedexpansion
set KWF="a.txt"
del $$.tmp $$$.tmp>nul 2>nul
:while
if "%~1" equ "" goto:a
ECHO %1
echo %~1>>$$.tmp
shift /1
goto:while
:a
for /r %%i in (*.txt) do (set n=1& if /i "%%~nxi" neq %KWF% call:CONVERT "%%~i")
del $$.tmp $$$.tmp&pause&goto:eof

:CONVERT
set/a tp=0
for /f "usebackq delims=" %%i in ("%~1") do (
set lb6=%%i
set lb6=!lb6:~0,6!
echo %%i>>$$$.tmp
for /f %%a in ($$.tmp) do if /i "!lb6!" equ "--%%a--" (echo %%i|findstr /g:%KWF%>NUL&&set/a tp=1)
if "!lb6!" equ "--LP--" (
if "!tp!" equ "1" (
echo 文件 "%~nx1" 第 !n! 段,符合要求……
type $$$.tmp>>$dest$.txt
set/a tp=0
type nul>$$$.tmp
)
set /a n+=1
)
)
GOTO:EOF
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
lxh623 +2 2009-04-26 13:17
17 发表于 2009-04-26 11:25 ·  中国 湖北 黄石 电信
中级用户
★★
积分 330
发帖 244
注册 2006-04-14 14:07
20年会员
UID 53823
性别 男
来自 湖北
状态 离线
修该了一点,提高了些效率,用法和上面一样,支持多个字段参数查找
@echo off&setlocal enabledelayedexpansion
set KWF="a.txt"
del $$.tmp $$$.tmp>nul 2>nul
:while
if "%~1" equ "" goto:a
echo %~1>>$$.tmp
shift /1
goto:while
:a
for /r %%i in (*.txt) do (set n=1& if /i "%%~nxi" neq %KWF% call:CONVERT "%%~i")
del $$.tmp $$$.tmp&pause&goto:eof

:CONVERT
set/a tp=0
for /f "usebackq delims=" %%i in ("%~1") do (
set lb6=%%i
set lb6=!lb6:~0,6!
echo %%i>>$$$.tmp
for /f %%a in ($$.tmp) do if /i "!lb6!" equ "--%%a--" if !tp! neq 1 (echo %%i|findstr /g:%KWF%>NUL&&set/a tp=1)
if "!lb6!" equ "--LP--" (
if "!tp!" equ "1" (
echo 文件 "%~nx1" 第 !n! 段,符合要求……
type $$$.tmp>>$dest$.txt
set/a tp=0
type nul>$$$.tmp
)
set /a n+=1
)
)
GOTO:EOF
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
lxh623 +2 2009-04-26 13:17
18 发表于 2009-04-27 01:23 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
积分 1,916
发帖 752
注册 2008-12-28 04:30
17年会员
UID 135147
性别 男
来自 广西
状态 离线
按照楼上的思路,改进了一下,不用临时文件,提搞了速度。

freeants001真厉害,竟然这样也能理解楼主的意思。佩服!

偶是看了freeants001写的代码才明白楼主的意思。

@echo off&setlocal enabledelayedexpansion
if "%1"=="" echo.最少给出一个条件&goto :eof
for %%a in (%*) do (set "tag=!tag! --%%a-- ")

for /f "delims=:" %%a in ('findstr /g:a.txt *.txt') do set ##%%a=1
set ##a.txt=

(for /f "delims==#" %%a in ('set ##') do (
set/a n=0,m=1
set test=#批处理#
for /f "delims=" %%b in ('type "%%a"') do (
set /a n+=1
set str!n!=%%b
for /f %%c in ("!n!") do (for /f %%d in ("!str%%c!") do (
if "!tag:%%d=!" neq "!tag!" set test=!test!%%b
) )
if "%%b" equ "------" (
echo.!test!|findstr /g:a.txt&&echo 文件 "%%~nxa" 第 !m! 段,符合要求>con&&for /l %%c in (1,1,!n!) do (echo.!str%%c!)
set/a n=0,m+=1
set test=#批处理#
)
)
))>b.txt

pause
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
lxh623 +2 2009-04-27 21:00
精简
=> 个人网志
19 发表于 2009-04-27 03:05 ·  中国 湖北 黄石 电信
中级用户
★★
积分 330
发帖 244
注册 2006-04-14 14:07
20年会员
UID 53823
性别 男
来自 湖北
状态 离线
楼上的速度确实要快一些,不过如果文件大小超过几MB后,速度就慢了
20 发表于 2009-04-27 04:28 ·  中国 四川 遂宁 电信
初级用户
积分 34
发帖 30
注册 2008-11-24 15:21
17年会员
UID 131962
性别 男
状态 离线
请问freeants001兄:
系统找不到$$.tmp $$$.tmp
批处理是不是基于前面的处理,我已经删除。因为曾经出来170多M。
现在想实在不行,先用freeants001兄的第一个导入再在文献软件中处理。
这个批处理采取先分段的办法,比较有创意,感谢!
另外,文件共207M。
21 发表于 2009-04-27 04:48 ·  中国 湖北 黄石 电信
中级用户
★★
积分 330
发帖 244
注册 2006-04-14 14:07
20年会员
UID 53823
性别 男
来自 湖北
状态 离线
系统找不到$$.tmp $$$.tmp,bat文件要放到要处理的文件目录中.
文件共207M,单个文件最大多少,如果没有上MB的话用netbenton兄的代码效率高些
22 发表于 2009-04-27 05:07 ·  中国 湖北 黄石 电信
中级用户
★★
积分 330
发帖 244
注册 2006-04-14 14:07
20年会员
UID 53823
性别 男
来自 湖北
状态 离线
受netbenton启发,去掉了分段临时文件,速度提高很多,用法不变
@echo off&setlocal enabledelayedexpansion
set KWF="a.txt"
del $$.tmp $$$.tmp $dest$.txt>nul 2>nul
if "%1" equ "" goto:eof
:while
if "%~1" equ "" goto:a
echo %~1>>$$.tmp
shift /1
goto:while
:a
for /r %%i in (*.txt) do (set /a n=1&if /i "%%~nxi" neq %KWF% call:CONVERT "%%~i")
del $$.tmp $$$.tmp&goto:eof

:CONVERT
set/a tp=0,i=0
for /f "usebackq delims=" %%i in ("%~1") do (
set /a i+=1
set lb6=%%i
SET tag!i!=%%i
set lb6=!lb6:~0,6!
for /f %%a in ($$.tmp) do if /i "!lb6!" equ "--%%a--" if !tp! neq 1 (echo %%i|findstr /g:%KWF%>NUL&&set/a tp=1)
if /i "!lb6!" equ "--LP--" (
if "!tp!" equ "1" (
echo 文件 "%~nx1" 第 !n! 段,符合要求……
call:e
set/a tp=0
)
set /a n+=1
set /a i=0
)
)
GOTO:EOF

:e
for /l %%i in (1,1,!i!) do echo !tag%%i!>>$dest$.txt
goto:eof
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
lxh623 +2 2009-04-28 10:11
23 发表于 2009-04-27 11:03 ·  中国 湖北 黄石 电信
中级用户
★★
积分 330
发帖 244
注册 2006-04-14 14:07
20年会员
UID 53823
性别 男
来自 湖北
状态 离线
最后一贴,其中参考了netbenton的代码,为提高效率,将设置文件件由a.txt更名为set.ini

@echo off&setlocal enabledelayedexpansion
set KWF="set.ini"
if "%1" equ "" goto:eof
del $dest$.txt>nul 2>nul
for /f "delims=" %%a in ('findstr /m /g:%KWF% *.txt') do (
set /a n=1,tp=0,i=0
for /f "usebackq delims=" %%i in ("%%~a") do (
set/a i+=1
set lb6=%%i
set tag!i!=%%i
set lb6=!lb6:~0,6!
for %%a in (%*) do if /i "!lb6!" equ "--%%a--" if !tp! neq 1 (echo %%i|findstr /g:%KWF%>NUL&&set/a tp=1)
if /i "!lb6!" equ "--LP--" (
if "!tp!" equ "1" (
echo 文件 "%%a" 第 !n! 段,符合要求……
for /l %%i in (1,1,!i!) do echo !tag%%i!>>$dest$.txt
set/a tp=0
)
set/a n+=1,i=0
)
)
)


[ Last edited by freeants001 on 2009-4-27 at 11:24 ]
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
lxh623 +2 2009-04-27 21:00
24 发表于 2009-05-01 06:31 ·  中国 湖北 十堰 电信
初级用户
积分 21
发帖 18
注册 2006-09-18 14:54
19年会员
UID 62969
状态 离线
我也来就大家帮我提一段文本,也就是这个网页中的内容http://www.luckfish.net/rising.htm,我只要这一段。
<td class="zzbg2"><img src="images/tubiao/rn.gif" width="28" height="32" align="absmiddle" /><strong> 瑞星杀毒软件网络版2008</strong></td>
<td valign="bottom"><img src="images/zzbgy2.jpg" width="12" height="30" /></td>
</tr>
</table></td>
<td>&nbsp;</td>
</tr>
</table>
<table width="100%" cellpadding="2" cellspacing="1" bgcolor="#C1DFF0" class="div_d">
<tbody>
<tr class="zzsbg">
<td width="120" align="center">程序名称</td>
<td width="70" align="center">版本</td>
<td width="80" align="center">文件大小</td>
<td width="60" align="center">更新时间</td>
<td width="37" align="center">下载</td>
<td width="310" align="center">使用说明</td>
</tr>
<tr bgcolor="#ffffff">
<td align="center" bgcolor="#ffffff">2008版升级包</td>
<td align="center" bgcolor="#ffffff">20.90.91</td>
<td align="center" bgcolor="#ffffff">152.39MB</td>
<td align="center" bgcolor="#ffffff">2009-04-29</td>
<td align="center" bgcolor="#ffffff"><a href="http://rsdown.rising.com.cn/netver/08netver/lkioje123/Update.exe">下载</a></td>
<td align="center" bgcolor="#ffffff" class="fent_17px"><div align="center">系统中心手动升级专用 (只能用“另存为”下载)</div></td>
</tr>
<tr bgcolor="#ffffff">
<td align="center" bgcolor="#F3F9FC">系统安装包</td>

[ Last edited by zxxhwlkj on 2009-5-1 at 06:33 ]
25 发表于 2009-05-06 22:38 ·  中国 河南 开封 电信
新手上路
积分 2
发帖 29
注册 2009-04-01 21:53
17年会员
UID 141828
性别 男
状态 离线
hhhhhhhhh
26 发表于 2009-05-06 22:38 ·  中国 河南 开封 电信
新手上路
积分 2
发帖 29
注册 2009-04-01 21:53
17年会员
UID 141828
性别 男
状态 离线
hhhhhhhhhhhhhhhhhhhhhhhhhh
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
yishanju -3 2009-05-07 00:49
论坛跳转: