通过 <section> 将 HTML 文件拆分为多个文件的最简单方法

问题描述

我有多个 HTML 文件,我想将它们拆分为由 section 标记分隔的单独文件。我认为 bash 或批处理文件是最简单的方法,但老实说,我对 Windows 批处理脚本的了解非常有限:P

示例文件结构:

mypage.html

<!DOCTYPE html>
<html>
    <head>
         ...
    </head>
<body>
    <!-- Section 1 -->
    <section class="foo">
        ...
    </section>
    <!-- Section 2 -->
    <section class="bar">
        ...
    </section>
    <!-- Section 3 -->
...
</body>
</html>

然后将这样枚举期望的结果:

C:/dir/mypage.html (original file)
C:/dir/sections/mypage-1.html (section 1)
C:/dir/sections/mypage-2.html (section 2)
...
C:/dir/sections/mypage-n.html

建议将不胜感激!

解决方法

tag=section
sed -n "/<$tag>/,/<\/$tag>/p" file

这应该是您的起点。