【发布时间】:2013-12-10 15:43:17
【问题描述】:
我不知道这样做的好方法(参见/awk/perl);我结合了html文件的多个章节,它具有以下结构
<a href="#chapter11">title</a>
<a href="#chapter12">title</a>
<a href="#chapter13">title</a>
<p>first chapter contents, multiple
pages</p>
<a href="#chapter21">title</a>
<a href="#chapter22">title</a>
<a href="#chapter23">title</a>
<p>Second chapter contents, multiple pages
more informations</p>
<a href="#chapter31">title</a>
<a href="#chapter32">title</a>
<a href="#chapter33">title</a>
<p>Third chapter contents, multiple pages
few more details</p>
我希望他们像下面这样重新组织
<a href="#chapter11">title</a>
<a href="#chapter12">title</a>
<a href="#chapter13">title</a>
<a href="#chapter21">title</a>
<a href="#chapter22">title</a>
<a href="#chapter23">title</a>
<a href="#chapter31">title</a>
<a href="#chapter32">title</a>
<a href="#chapter33">title</a>
<p>first chapter contents, multiple
pages</p>
<p>Second chapter contents, multiple pages
more informations</p>
<p>Third chapter contents, multiple pages
few more details</p>
我在一个 html 中有五个章节来重新组织它们。我试图采用 sed 保持缓冲区,但据我所知,这似乎很困难。我不限于 sed 或 awk。任何帮助将不胜感激,谢谢。
编辑
抱歉修改了源文件,它也有几行并不总是以
<a or <p
在 sed 中是否有类似逆向选择的脚本,比如
/^<a!/p/
【问题讨论】: