标题: [已结]批处理筛选保留文本指定内容
[打印本页]
作者: w1314ich
时间: 2008-4-1 21:19
标题: [已结]批处理筛选保留文本指定内容
有一个网页首页文件,改成TXT打开后,里面有很多内容,如下:
===============================================
<html>
<head>
<title>XXXXXXXXXXX</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="style.css">
</head>
<body background=images/bg.gif leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>
<TABLE WIDTH=775 BORDER=0 CELLPADDING=0 CELLSPACING=0 align=center>
<TR>
<TD ROWSPAN=2>
<IMG SRC="images/title_01.gif" WIDTH=644 HEIGHT=81 ALT=""></TD>
<TD>
<a href="gywmen.asp"><IMG SRC="images/title_02.gif" WIDTH=131 HEIGHT=17 border=0></a></TD>
</TR>
<TR>
<TD>
<IMG SRC="images/title_03.gif" WIDTH=131 HEIGHT=64 ALT=""></TD>
</TR>
</TABLE>
<TABLE WIDTH=775 BORDER=0 CELLPADDING=0 CELLSPACING=0 align=center bgcolor=#ffffff>
<TR>
<TD>
<a href="index.asp"><IMG SRC="images/botton_up_01.gif" WIDTH=37 HEIGHT=25 border=0 onmouseover="JavaScript:this.src='images/botton_over_01.gif'" onmouseout="JavaScript:this.src='images/botton_up_01.gif'" onclick="JavaScript:this.src='images/botton_over_01.gif'" style="cursor:hand"></a></TD>
<TD>
<a href="xhjs1.asp"><IMG SRC="images/botton_up_02.gif" WIDTH=70 HEIGHT=25 border=0 onmouseover="JavaScript:this.src='images/botton_over_02.gif'" onmouseout="JavaScript:this.src='images/botton_up_02.gif'" onclick="JavaScript:this.src='images/botton_over_02.gif'" style="cursor:hand"></a></TD>
<TD>
<a href="hyzj1.asp"><IMG SRC="images/botton_up_03.gif" WIDTH=70 HEIGHT=25 border=0 onmouseover="JavaScript:this.src='images/botton_over_03.gif'" onmouseout="JavaScript:this.src='images/botton_up_03.gif'" onclick="JavaScript:this.src='images/botton_over_03.gif'" style="cursor:hand"></a></TD>
<TD>
<a href="xhxx1.asp"><IMG SRC="images/botton_up_04.gif" WIDTH=71 HEIGHT=25 border=0 onmouseover="JavaScript:this.src='images/botton_over_04.gif'" onmouseout="JavaScript:this.src='images/botton_up_04.gif'" onclick="JavaScript:this.src='images/botton_over_04.gif'" style="cursor:hand"></a></TD>
<TD>
<a href="hydt1.asp"><IMG SRC="images/botton_up_05.gif" WIDTH=71 HEIGHT=25 border=0 onmouseover="JavaScript:this.src='images/botton_over_05.gif'" onmouseout="JavaScript:this.src='images/botton_up_05.gif'" onclick="JavaScript:this.src='images/botton_over_05.gif'" style="cursor:hand"></a></TD>
<TD>
<a href="jlhz1.asp"><IMG SRC="images/botton_up_06.gif" WIDTH=70 HEIGHT=25 border=0 onmouseover="JavaScript:this.src='images/botton_over_06.gif'" onmouseout="JavaScript:this.src='images/botton_up_06.gif'" onclick="JavaScript:this.src='images/botton_over_06.gif'" style="cursor:hand"></a></TD>
<TD>
<a href="pxtd1.asp"><IMG SRC="images/botton_up_07.gif" WIDTH=71 HEIGHT=25 border=0 onmouseover="JavaScript:this.src='images/botton_over_07.gif'" onmouseout="JavaScript:this.src='images/botton_up_07.gif'" onclick="JavaScript:this.src='images/botton_over_07.gif'" style="cursor:hand"></a></TD>
<TD>
<a href="zcfg1.asp"><IMG SRC="images/botton_up_08.gif" WIDTH=68 HEIGHT=25 border=0 onmouseover="JavaScript:this.src='images/botton_over_08.gif'" onmouseout="JavaScript:this.src='images/botton_up_08.gif'" onclick="JavaScript:this.src='images/botton_over_08.gif'" style="cursor:hand"></a></TD>
<TD>
<a href="wscy.asp"><IMG SRC="images/botton_up_09.gif" WIDTH=72 HEIGHT=25 border=0 onmouseover="JavaScript:this.src='images/botton_over_09.gif'" onmouseout="JavaScript:this.src='images/botton_up_09.gif'" onclick="JavaScript:this.src='images/botton_over_09.gif'" style="cursor:hand"></a></TD>
<TD>
<a href="wlzwhjj.asp"><IMG SRC="images/botton_up_10.gif" WIDTH=70 HEIGHT=25 border=0 onmouseover="JavaScript:this.src='images/botton_over_10.gif'" onmouseout="JavaScript:this.src='images/botton_up_10.gif'" onclick="JavaScript:this.src='images/botton_over_10.gif'" style="cursor:hand"></a></TD>
<TD>
<a href="http://www.ec315.cn/onlinets.asp" target=_blank><IMG SRC="images/botton_up_11.gif" WIDTH=68 HEIGHT=25 border=0 onmouseover="JavaScript:this.src='images/botton_over_11.gif'" onmouseout="JavaScript:this.src='images/botton_up_11.gif'" onclick="JavaScript:this.src='images/botton_over_11.gif'" style="cursor:hand"></a></TD>
</TR>
</TABLE>
<table width=775 border=0 cellpadding=0 cellspacing=0 align=center valign=top bgcolor=#ffffff>
<tr>
<td height=100% valign=top>
<table border=0 cellspacing=0 cellpadding=0 width=178 height=100% align=center valign=top bgcolor=#f2f2f2>
<script language="javascript">
function submitform()
{
frm_login.submit();
}
</script>
<script language="javascript">
function cleartext() {
if (document.Form1.text1.value=='输入关键字')
document.Form1.text1.value='';
}
</script>
<tr>
<td valign=top>
<form name="frm_login" method="post" action="chk_login.asp">
<table border=0 cellspacing=0 cellpadding=0 width=178 height=103 align=center valign=top>
<tr>
<td valign=top height=22><img src="images/login_01.gif"></td>
</tr>
<tr>
<td valign=top height=80 bgcolor=#F2F2F2 align=center>
<table border=0 cellspacing=0 cellpadding=0 width=150 height=60 align=center valign=top>
<tr>
<td class=f2>用户名:</td>
<td><INPUT type="text" name="username" class=input1></td>
</tr>
<tr>
<td class=f2>密码:</td>
<td><INPUT type="password" id="password" name="password" class=input1></td>
</tr>
<tr><td height=6 colspan=2></td></tr>
<tr>
<td><input type=image onClick="submitform()" src=images/login_02.gif border=0 id=image1 name=image1></td>
<td><a href="wsdj.asp"><img src="images/login_03.gif" border=0></a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign=top height=1 bgcolor=#C9C9C9></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td height=8></td>
</tr>
<tr>
<td>
<table border=0 cellspacing=0 cellpadding=1 width=170 height=66 align=center valign=top bgcolor=#CBCBCB>
<tr>
<td>
<table border=0 cellspacing=0 cellpadding=0 width=168 height=64 align=center valign=top bgcolor=#ffffff>
<tr>
<td valign=top><img src="images/search_01.gif"></td>
</tr>
<form action=search.asp method=post ID="Form1" name=Form1>
<tr>
<td valign=top align=center>
<INPUT onfocus="cleartext();" type="text" id=text1 name=text1 value=输入关键字 class=input2>
<input type=image src=images/search_02.gif border=0 id=image1 name=image1>
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height=8 align=center valign=top></td>
</tr>
<tr>
<td align=center><a href=mailto:seca@sh-ec.org.cn><img src="images/mail.gif" border=0></a></td>
</tr>
<tr>
<td height=8 align=center valign=top></td>
</tr>
<tr>
<td height=8 align=center valign=top></td>
</tr>
<tr>
<td align=center valign=top><a href="qikan.asp"><img src="images/publication.gif" border=0></a></td>
</tr>
<tr>
<td height=8 align=center valign=top></td>
</tr>
<tr>
<td align=center valign=top>
<table border=0 cellspacing=0 cellpadding=1 width=170 height=250 align=center valign=top bgcolor=#CBCBCB>
<tr>
<td>
<table border=0 cellspacing=0 cellpadding=0 width=168 height=248 align=center valign=top bgcolor=#ffffff>
<tr>
<td valign=top><img src="images/online_research_01.gif"></td>
</tr>
<tr>
<td valign=top align=center class=f2><script src="admin/vote/vote_js.asp"></script>
</td>
</tr>
<tr>
<td valign=top align=center height=8></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height=8 align=center valign=top></td>
</tr>
<tr>
<td align=center valign=top><a href="zddh.asp"><img src="images/webnavigation_logo.gif" border=0></a></td>
</tr>
<tr>
<td height=8 align=center valign=top></td>
</tr>
<tr>
<td align=center valign=top><a href="lxwm.asp"><img src="images/contactUS.gif" border=0></a></td>
</tr>
<tr>
<td height=100% align=center valign=top></td>
</tr>
</table>
</td>
<td width=1 bgcolor=#c9c9c9 height=100%></td>
<td>
<table width=596 border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
<td height=103><a href="http://www.ec315.cn"><img src="images/ec315.gif" border=0></a></td>
</tr>
<tr>
<td width=596 height=25 background="images/bg_01.gif"></td>
</tr>
<tr>
<td>
<table width=596 border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
<td height=80% width=412>
<table width=412 border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
<td>
<table width=394 border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
<td>
<img src="images/center_01.gif" width=144 height=32 alt=""></td>
<td>
<img src="images/center_02.gif" width=24 height=32 alt=""></td>
<td colspan=2>
<a href="xhxx1.asp?id=42"><img src="images/center_03.gif" width=226 height=32 border=0></a></td>
</tr>
<tr>
<td width=144 height=200 bgcolor=#c0c2ca align=center class=f1>
<DIV><A href="http://210.13.118.19/gather/dataGather/index.jsp"></A></DIV><A href="http://210.13.118.19/gather/dataGather/index.jsp"><IMG height=99 alt=上海市电子商务统计网上直报系统登录 src="http://www.sh-ec.org.cn/upload/tongji_logo9.JPG" width=142 align=center border=0></A>
<P align=left><FONT size=2>上海市电子商务统计网上直报系统登录</FONT></P></FONT>,
</td>
<td width=24 height=200 background="images/center_05.gif"></td>
<td width=219 height=200>
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td class=f_time>·<a href="news.asp?id=842" class=af0 target="_blank">上海电子商务行业协会推动网上诚信建设</a></td>
</tr>
<tr>
<td class=f_time>·<a href="news.asp?id=835" class=af0 target="_blank">上海市电子商务行业协会第一届第六次理事会会议召开</a></td>
</tr>
<tr>
<td class=f_time>·<a href="news.asp?id=832" class=af0 target="_blank">传统大厂变"网上大户"上海B2B电子交易破2000亿</a></td>
</tr>
<tr>
<td class=f_time>·<a href="news.asp?id=831" class=af0 target="_blank">统计快报显示,2007全年上海市电子商务交易额达2407.3亿</a></td>
</tr>
<tr>
<td class=f_time>·<a href="news.asp?id=830" class=af0 target="_blank">2007年上海电子商务交易额突破2400亿</a></td>
</tr>
<tr>
<td class=f_time>·<a href="news.asp?id=829" class=af0 target="_blank">“2008虹口区网上创业技能大赛”成功举办</a></td>
</tr>
<tr>
<td class=f_time>·<a href="news.asp?id=828" class=af0 target="_blank">“展望08”暨上海市电子商务行业协会春节茶话会于近日成功举办</a></td>
</tr>
</table>
</td>
<td width=7 height=200 background="images/center_07.gif"></td>
</tr>
<tr>
<td>
<img src="images/center_08.gif" width=144 height=12 alt=""></td>
<td>
<img src="images/center_09.gif" width=24 height=12 alt=""></td>
<td>
<img src="images/center_010.gif" width=219 height=12 alt=""></td>
<td>
<img src="images/center_011.gif" width=7 height=12 alt=""></td>
</tr>
</table>
</td>
</tr>
<tr><td height=15></td></tr>
<tr>
<td>
<table width=394 border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
<td>
<table width=184 border=0 cellpadding=0 cellspacing=0>
<tr>
<td>
<a href="wscy.asp"><img src="images/center_1_01.gif" width=184 height=59 alt="" border="0"></a></td>
</tr>
<tr>
<td background="images/center_1_02.gif" width=184 height=84>
<TABLE cellSpacing=0 cellPadding=0 width=160 align=center border=0>
<TBODY>
<TR>
<TD class=f_time><A href="wscy_news.asp?id=66"> · 网上卖家诚信承诺登记</A><BR><A href="wscy_news.asp?id=56"> · 创业快讯</A><BR><A href="wscy_news.asp?id=58"> · 创业程序</A><BR><A href="wscy_news.asp?id=57"> · 创业成功案例1 </A></TD></TR></TBODY></TABLE>
</td>
</tr>
<tr>
<td>
<img src="images/center_1_03.gif" width=184 height=14 alt=""></td>
</tr>
</table>
</td>
<td width=6></td>
<td>
<table width=184 border=0 cellpadding=0 cellspacing=0>
<tr>
<td>
<a href="jlhz1.asp"><img src="images/center_2_01.gif" width=184 height=59 alt="" border="0"></a></td>
</tr>
<tr>
<td background="images/center_1_02.gif" width=184 height=84>
<TABLE cellSpacing=0 cellPadding=0 width=160 align=center border=0>
<TBODY>
<TR>
<TD class=f_time>
<P>
<TABLE cellSpacing=0 cellPadding=0 width=160 align=center border=0>
<TBODY>
<TR>
<TD class=f_time><A href="jlhz1.asp?id=51">· 会展论坛动态</A><BR><A href="jlhz1.asp?id=52">· 历次展会信息</A><BR><A href="jlhz1.asp?id=53">· 历次论坛资料</A></TD></TR></TBODY></TABLE></P></TD></TR></TBODY></TABLE>
</td>
</tr>
<tr>
<td>
<img src="images/center_1_03.gif" width=184 height=14 alt=""></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr><td height=15></td></tr>
</table>
</td>
<td height=60% width=183 valign=top>
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td height=60% width=2 background="images/bg_02.gif"></td>
<td height=60% width=181 background="images/bg_03.gif">
<table border=0 cellpadding=0 cellspacing=0 width=181 valign=top>
<tr><td height=5></td></tr>
<tr>
<td>
<table border=0 cellspacing=0 cellpadding=1 width=170 height=250 align=center valign=top bgcolor=#cbcbcb>
<tr>
<td>
<!--友情连接-->
<TABLE height=248 cellSpacing=0 cellPadding=0 width=168 align=center bgColor=#ffffff border=0 valign="top">
<TBODY>
<TR>
<TD vAlign=top><A href="http://www.sh-ec.org.cn/yqlj.asp"><IMG height=33 src="http://www.sh-ec.org.cn/upload/friend_research.JPG" width=168 border="0"></A></TD></TR>
<TR>
<TD vAlign=top> </TD></TR>
<TR>
<TD vAlign=top align=middle><A href="http://www.shanghai.gov.cn" target=_blank><IMG height=46 src="http://www.sh-ec.org.cn/upload/logo_shgov.JPG" width=158 border=0></A><BR></TD></TR>
<TR>
<TD vAlign=top> </TD></TR>
<TR>
<TD vAlign=top align=middle><A href="http://www.shanghaiit.gov.cn" target=_blank><IMG height=55 src="http://www.sh-ec.org.cn/upload/shitgovlogo.JPG" width=159 border=0></A><BR></TD></TR>
<TR>
<TD vAlign=top> </TD></TR>
<TR>
<TD vAlign=top align=middle><A href="http://www.sh-ec.org.cn/wscy_news.asp?id=66" target=_blank ><IMG height=68 src="http://www.sh-ec.org.cn/upload/cecalogo.JPG" width=157 border=0></A><BR></TD></TR>
<TR>
<TD vAlign=top></TD></TR>
<TR>
<TD vAlign=top align=right>
<P><IMG height=7 src="http://www.sh-ec.org.cn/admin/include/images/more.gif" width=35 border=0 target="_blank"></P></TD></TR>
<TR>
<TD vAlign=top align=middle>
<P align="center"><A href="http://www.sh-ec.org.cn/wscy_news.asp?id=66" target=_blank ><IMG height=91 src="http://www.sh-ec.org.cn/upload/seca_mjcn.JPG" width=158 border=0></A></P></TD></TR><TR>
<TD vAlign=top align=middle>
<P align="center"><A href="http://www.sh-ec.org.cn/news.asp?id=820" target=_blank ><IMG height=185 src="http://www.sh-ec.org.cn/upload/shec07report-cover.jpg " width=135 border=0></A></P></TD></TR></TBODY></TABLE>
</td>
</tr>
</table>
</td>
</tr>
<tr><td height=5></td></tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width=596 border=0 cellpadding=0 cellspacing=0 align=center >
<tr>
<td colspan="4"><a href="hylink.asp"><img src="images/center_3_01.jpg" width="595" border=0></a></td>
</tr>
<tr>
<td height="100" class=td-y1 align="center"><a href="http://www.guanghua.sh.cn" target="_blank"><img border="0" src="images\upload\guanghua.gif" alt="上海复旦光华信息科技股份有限公司" width="130" height="80"></a></td>
<td height="100" class=td-y1 align="center"><a href="http://www.oa123.com" target="_blank"><img border="0" src="images\upload\jdhg.gif" alt="上海交大慧谷信息产业股份有限公司" width="130" height="80"></a></td>
<td height="100" class=td-y1 align="center"><a href="http://www.easipass.com" target="_blank"><img border="0" src="images\upload\ytgj.gif" alt="上海亿通国际股份有限公司" width="130" height="80"></a></td>
<td height="100" class=td-y1 align="center"><a href="http://www.bsteel.com" target="_blank"><img border="0" src="images\upload\dfgt.gif" alt="东方钢铁电子商务有限公司" width="130" height="80"></a></td>
</tr><tr>
<td height="100" class=td-y1 align="center"><a href="http://www.962222.net" target="_blank"><img border="0" src="images\upload\sbzx.gif" alt="上海市社会保障和市民服务信息中心" width="130" height="80"></a></td>
<td height="100" class=td-y1 align="center"><a href="http://www.shmec.com.cn" target="_blank"><img border="0" src="images\upload\me.gif" alt="上海爱姆意机电设备连锁有限公司" width="130" height="80"></a></td>
<td height="100" class=td-y1 align="center"><a href="http://www.ebay.com.cn" target="_blank"><img border="0" src="images\upload\eachet.gif" alt="亿贝易趣网络信息服务(上海)有限公司" width="130" height="80"></a></td>
<td height="100" class=td-y1 align="center"><a href="http://www.staples.sh.cn" target="_blank"><img border="0" src="images\upload\stb.gif" alt="史泰博商贸有限公司" width="130" height="80"></a></td>
</tr><tr>
</table>
</td>
</tr>
</table>
<style type="text/css">
<!--
a:link {
text-decoration: none;
color: #000000;
}
a:visited {
text-decoration: none;
color: #000000;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style><TABLE WIDTH=775 BORDER=0 CELLPADDING=0 CELLSPACING=0 align=center>
<TR>
<TD height=1 bgcolor=#9B9B9B></TD>
</TR>
<TR>
<TD height=26 bgcolor=#E5E6E8 class=f2 align=center> 版权所有 </TD>
</TR>
</tr>
<TR>
<TD height=1 bgcolor=#9B9B9B></TD>
</TR>
</TABLE>
</body>
</html>
===============================================
我想把里面以asp为后缀名的文件名保留下来(保留下来的文件名包括后缀名)其他所有的东西都不要,最后生成的结果如下:
===============================================
gywmen.asp|index.asp|xhjs1.asp|hyzj1.asp|xhxx1.asp|hydt1.asp|jlhz1.asp|pxtd1.asp|zcfg1.asp|wscy.asp|wlzwhjj.asp|wsdj.asp|qikan.asp|zddh.asp|lxwm.asp|xhxx1.asp|news.asp|wscy.asp|wscy_news.asp|yqlj.asp|hylink.asp
===============================================
请问能不能用批处理实现
[
Last edited by HAT on 2009-1-2 at 01:41 ]
作者: w1314ich
时间: 2008-4-1 21:42
自己顶一下~~~
作者: w1314ich
时间: 2008-4-1 22:24
有人能帮帮忙吗 非常感谢
作者: terse
时间: 2008-4-1 22:44
用批处理 可怕很难 因为特殊字符
@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
作者: w1314ich
时间: 2008-4-1 23:16
<a href="news.asp?id=842" 中的news.asp不能提取出来
还有 <form name="frm_login" method="post" action="chk_login.asp">
中的chk_login.asp <form action=search.asp method=post ID="Form1" name=Form1> 中的search.asp <a href="xhxx1.asp?id=42"> 中的xhxxq.asp等被忽略了
输出的结果是
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 ]
作者: bat-zw
时间: 2008-4-1 23:19
我搞了个把小时,只能回句太难了,很多提不出来啊,主要是情况太复杂了。
作者: w1314ich
时间: 2008-4-1 23:29
非常感谢 你能把刚刚批处理的注释帮我写写么 最好能详细点 谢谢
作者: 26933062
时间: 2008-4-1 23:43
苯办法,文件名中不能含有#号。
:
@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
作者: terse
时间: 2008-4-1 23:45
@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"
作者: terse
时间: 2008-4-1 23:47
发了才知道有了
作者: ThinKing
时间: 2008-4-2 08:11
为什么不直接:
grep -oE "\w+\.asp" urfile.html
呢?
作者: bat-zw
时间: 2008-4-2 13:32
Quote: |
Originally posted by w1314ich at 2008-4-1 23:29:
非常感谢 你能把刚刚批处理的注释帮我写写么 最好能详细点 谢谢 |
|
Quote: |
@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" |
|
应楼主要求并尽我的能力为TERSE的这段精彩代码写下解释如下(如有错误和不到之处请谅解并指教):
批处理首先通过第一个for循环开启变量延迟以":"为分隔符对a.txt中每段字符串中的特殊字符(:"")进行变量替换为无,同时将特殊字符(?><)替换为空格" "(是为后面的for循环中delims= 做准备工作);
然后对替换后的这段字符串进行if判断是否为空,如不是空就进入第二个for循环又用if对以" "为分格符的第一个字符串%%i进行判断是否含有以.asp为后缀名的文件名(在这里使用了变量扩充%%~xi将变量%%i扩充到文件扩展名),如果有则将这串字符(%%i)添加输入到back.txt中,如不含有(else)则跳转到标签为lp的下一个for循环,并将%%i后所有字串符"%%j变量"传递给下一个for循环(注意在这里用双引号将%%j引起来是为了使下一个for循环中能正确识别含有空格的变量%%j);
在最后一个for循环中其实是不断重复前一个for循环的工作直到最后一个后缀名为.asp的字符串被取出添加到back.txt中,只不过是要在这里运用%%~1去除变量的双引号扩充变量%%~1(从上一个for循环中传递过来的加了双引号的变量"%%j")。
又是一个很难解释的过程,汗。。。。。。。。。。。。。。。
[
Last edited by zw19750516 on 2008-4-2 at 01:41 PM ]
作者: bjsh
时间: 2008-4-2 14:38
如果是我的话, 我会用python来解析。
还算相当简单的吧, 效率当然比批处理更高。。。
作者: abcd
时间: 2008-4-2 14:47
处理此问题,VBS更简单高效。
何必在一棵树上吊死呢?
作者: bat-zw
时间: 2008-4-2 14:51
我不同意abcd的意见,我们处理这个问题是为了得到提高,不为了别的。
[
Last edited by zw19750516 on 2008-4-2 at 02:52 PM ]
作者: abcd
时间: 2008-4-2 15:45
在这里的大部分友人,学习或接触脚本
是为了给生活或工作带来效率。
这也是大部分脚本开发者的目的。
而有更好快捷高效的方法不用,而退而求其次,是否有些舍本求末?
作者: plp626
时间: 2008-4-2 16:29
我是因为它好玩,简洁才学.不像其他高级语言还类了什么的,烦不烦,完成一个简单任务编译的文件妈的快1M了.
还有它很方便,会用记事本就可以了.
作者: w1314ich
时间: 2008-4-2 20:57
@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
)
cd.>asp.txt
for /f "eol= delims=" %%i in (b.txt) do (
findstr /xc:"%%i" asp.txt >nul 2>nul||echo %%i>>asp.txt
)
del b.txt
start asp.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
谢谢各位仁兄的慷慨相助 互联网因为你们才变得精彩
以上我加入了剔除重复行的代码,实现了剔除重复行的
功能,不知道用什么方法能实现输出 a.asp|b.asp|c.asp...的结果
作者: netbenton
时间: 2009-1-2 01:04
标题: 这样就全搞定了!
@echo off&setlocal enabledelayedexpansion
for /f "tokens=* delims=:" %%a in ('findstr /n ".asp" a.txt') do (
set var=%%a
set var=!var:/= !
set var=!var:"= !
set var=!var:?= !
set var=!var::= !
set var=!var:^>= !
set var=!var:^<= !
for %%i in (!var!) do (
set aaa=%%i
set aaa=!aaa:~-4!
if !aaa!==.asp set bbb=!bbb!^|%%i
)
)
set bbb=!bbb:~1!
echo =================================================================
echo !bbb!
echo =================================================================
pause