如何删除 vi 中与正则表达式匹配的行?

发布于 2024-11-25 08:51:52 字数 906 浏览 1 评论 0原文

我有一个大文本文件,其中包含我试图删除的以下标题。例如:

1 Nephi 2:13
 13 Neither did they believe that Jerusalem, that great city,
could be destroyed according to the words of the prophets. And
they were like unto the Jews who were at Jerusalem, who sought to
take away the life of my father.
1 Nephi 2:14
 14 And it came to pass that my father did speak unto them in the
valley of Lemuel, with power, being filled with the Spirit, until
their frames did shake before him. And he did confound them,
that they durst not utter against him; wherefore, they did as he
commanded them.
1 Nephi 2:15
 15 And my father dwelt in a tent.
1 Nephi 2:16

我正在尝试删除包含“1 Nephi 2:16”的整行,因此我正在 vi 中寻找与包含书籍和经文参考的整行匹配的正则表达式。

以下是需要匹配的示例书籍和诗句组合的列表

1 Nephi 2:16
Mormon 3:7
Alma 32:27
Words of Mormon 1:3

I have a large text file that has the following headings that I'm trying to delete out. For example:

1 Nephi 2:13
 13 Neither did they believe that Jerusalem, that great city,
could be destroyed according to the words of the prophets. And
they were like unto the Jews who were at Jerusalem, who sought to
take away the life of my father.
1 Nephi 2:14
 14 And it came to pass that my father did speak unto them in the
valley of Lemuel, with power, being filled with the Spirit, until
their frames did shake before him. And he did confound them,
that they durst not utter against him; wherefore, they did as he
commanded them.
1 Nephi 2:15
 15 And my father dwelt in a tent.
1 Nephi 2:16

I'm trying to delete the entire line containing the "1 Nephi 2:16", so I'm looking for a regular expression in vi that would match entire line containing book and verse reference.

Below is a list of example book and verse combinations it needs to match

1 Nephi 2:16
Mormon 3:7
Alma 32:27
Words of Mormon 1:3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

避讳 2024-12-02 08:51:52

重复混沌的答案:如果您可以确定以冒号分隔的两个数字结尾的行的任何事件都将是标题:

:g/.* [0-9]\+:[0-9]\+$/d

riffing on chaos's answer: if you can be sure that any incidence of a line ending with two numbers separated by a colon will be a header:

:g/.* [0-9]\+:[0-9]\+$/d
回忆躺在深渊里 2024-12-02 08:51:52
:g/1 Nephi 2:16/d
:g/Mormon 3:7/d
:g/Alma 32:27/d
:g/Words of Mormon 1:3/d

这些命令的意思是“全局(g)匹配此正则表达式(/.../)并删除(d)它出现的每一行” 。

:g/1 Nephi 2:16/d
:g/Mormon 3:7/d
:g/Alma 32:27/d
:g/Words of Mormon 1:3/d

Those commands mean "globally (g) match this regex (/.../) and delete (d) each line where it occurred".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文