小编Lor*_*996的帖子

How does shell select content within the keyword range?

这是一个 HTML 文件,在 HTML 文件中包含大量<section>... </section>内容,其格式如下。

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<section>
<div>
<header><h2>This is a title (RfQVthHm)</h2></header>
More HTML codes...
</div>
</section>

<section>
<div>
<header><h2>This is a title (UaHaZWvm)</h2></header>
More HTML codes...
</div>
</section>

<section>
<div>
<header><h2>This is a title (vxzbXEGq)</h2></header>
More HTML codes...
</div>
</section>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我需要提取第二个<section>...</section>内容。

这是预期的输出。

<section>
<div>
<header><h2>This is a title (UaHaZWvm)</h2></header>
More HTML codes...
</div>
</section>
Run Code Online (Sandbox Code Playgroud)

我注意到我可以先查找UaHaZWvm字符(以及前面 2 行),直到遇到下一个</section>.

OP的努力(在评论中提到): grep -o …

shell awk grep sed

2
推荐指数
1
解决办法
136
查看次数

标签 统计

awk ×1

grep ×1

sed ×1

shell ×1