Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete the lines matching a regex in vi?

Tags:

regex

vi

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
like image 584
random21 Avatar asked Oct 19 '25 02:10

random21


1 Answers

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
like image 52
jcomeau_ictx Avatar answered Oct 22 '25 04:10

jcomeau_ictx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!