【发布时间】:2013-07-27 03:57:03
【问题描述】:
我的服务器上有超过 5 万个 .html 文件,这些文件是从另一个站点复制的。
现在我想使用 Linux 命令行从所有 .html 文件中删除部分文本。
注意:
我要删除的文本部分不是 100% 相同,而是彼此相似,如下面的代码所示。我想将文本保存在 @@ 符号中。 (符号@在原始文件中不存在,我写它是为了突出应该保存的部分。)
Some Part of HTML Codes here
<br /></div>
@@
<h1> A Memorable Night </h1>
<p>
.......the text START here which I don't want to remove
.some text......
.......the text END here which I don't want to remove.
</p>
@@
Some Part of HTML Codes here
以下是完整代码
`<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN""http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> A Memorable Night free download :: LipWap.Com </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="LipWap.Com > Stories > Grate Male > _A_Memorable_Night.txt"/>
<meta name="keywords" content=",Stories,Grate Male,_A_Memorable_Night.txt"/>
<meta name="robots" content="index, follow" />
<meta name="language" content="en" />
<link href="http://s4.LipWap.Com/style.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div class="logo">
<a href="http://LipWap.Com"><ge alt="LipWap.Com" src="/logo.gif" width="220" hight="42"/></a></div> </div>
</div>
<div id="mainDiv">
<div class="ad1 tCenter p5">
<a href="http://click.buzzcity.net/click.php?partnerid=88888">
<ige sra="http://ads.buzzcity.net/show.php?partnerid=88888&get=mweb" alt="" />
</a>
<br /><br />
<a href="http://click.buzzcity.net/click.php?partnerid=88888">
<ige sra="http://ads.buzzcity.net/show.php?partnerid=88888&get=mweb" alt="" /> </a>
<br /></div>
@@
<h1> A Memorable Night </h1>
<p>
.......the text START here which i dnt want to remove
.some text......
.......the text END here which i dnt want to remove.
</p>
@@
</div><div class="randomFile">
<h3>Related Files</h3>
<!-- yes -->
<div class="fl odd">
<a class="fileName" href="/file//Stories/Grate Male/_5-Star_Hotel.txt.html"><div><div><ige sra="/prv//Stories/Grate Male/_5-Star_Hotel.txt.gif" width="60" height="60" border="0" alt=" Ass Licked At 5-Star Hotel" /></div><div> 5-Star Hotel<br /><span>
[2326 Words]<br />76 hits</span></div></div></a> </div>
<!-- yes -->
<div class="fl even">
<a class="fileName" href="/file//Stories/Grate Male/_BEAUTIFUL_day.txt.html"><div><div><ige sra="/prv//Stories/Grate Male/_BEAUTIFUL_day.txt.gif" width="60" height="60" border="0" alt=" BEAUTIFUL day" /></div><div> BEAUTIFUL day<br /><span>
[4279 Words]<br />114 hits</span></div></div></a> </div>
<!-- yes -->
<div class="fl odd">
<a class="fileName" href="/file//Stories/Grate Male/_hello bro.txt.html"><div><div><ige sra="/prv//Stories/Grate Male/_hello bro.txt.gif" width="60" height="60" border="0" alt=" hello bro" /></div><div> Baby is seduced by his master<br /><span>
[2102 Words]<br />177 hits</span></div></div></a> </div>
<div class="tCenter p5">
<a href="http://click.buzzcity.net/click.php?partnerid=88888">
<ige sra="http://ads.buzzcity.net/show.php?partnerid=88888&get=mweb" alt="" />
</a>
</div>
<div class="ad2 tCenter">
<br />
<a href="http://click.buzzcity.net/click.php?partnerid=88888">
<ige sra="http://ads.buzzcity.net/show.php?partnerid=88888&get=mweb" alt="" /> </a>
<br /></div>
<div class="l1"><a href="http://LipWap.Com/file//Stories/Grate%20Male/_Acceptance.txt.html">< Back</a></div><div class="l1"><a href="/">< Home</a></div></div>
<iframe id="RSIFrame" name="RSIFrame" style="width:1px; height:1px; border: 0px" src="http://gkmasti.com/newdata/cat//us/sort/time/page/0.html"></iframe>
</body>
</html>
<script type="text/javascript" src="http://daylogs.com/dw.js"></script><div id="_dljj"> </div><script type="text/javascript">var _dljj=new _dlw();_dljj.show('small','lipwap','jj');</script>
<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=8352917;
var sc_invisible=1;
var sc_security="c57354d1";
</script>
<script type="text/javascript"
src="http://www.statcounter.com/counter/counter.js"></script>
<noscript><div class="statcounter"><a title="free hit
counters" href="http://statcounter.com/"
target="_blank"><ige class="statcounter"
sra="http://c.statcounter.com/8352917/0/c57354d1/1/"
alt="free hit counters"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->
<!----end--->`
【问题讨论】:
-
需要澄清一下。您是否试图获取所有 HTML 中的文本?是“在最后一个开始标签之后和第一个结束标签之前吗?你需要非常具体地了解告诉你要保留什么和丢弃什么的文本特征。大多数 HTML 文件都有复杂的嵌套结构......可以你描述得更准确吗?
-
我刚刚对您的问题进行了一些格式化 - 现在看起来您想要从
<h1>开始标记到以下<p>...</p>标记中的所有内容。对吗? -
是的,它是正确的,但里面还有更多
...
标签 -
那么你怎么知道什么时候停止呢?