Re: How can I delete entire lines based on a search expression in vi?

Learning precision when deploying regular expressions will keep you from matching when you *don't* want to match as well as allow you to match when you should. Form the good habits early and save yourself countless hours of pain.

Re: How can I delete entire lines based on a search expression in vi?

I didn't need to be pedantic since this is a XML file with serious parse errors. So, things like <AccountType>,<EMail/>, <Contact/>... could safely be removed. But now it gets harder (at least for me, a DBA): I need to add stuffs to the file.

For example, I would like to add the line "<SelfBillingIndicator>0</SelfBillingIndicator>﻿" before each line "</Customer>"

Re: How can I delete entire lines based on a search expression in vi?

By the time your requirements get as complicated as this, you should not want to "solve" that in vi

I'd suggest perl, but I am clearly biased

Take the suggestions from this thread and create yourself a simple perl script that modifies the original file and outputs the result to *another* file, so you can then alter the script as long and often as you want till you get where you want to be.

Of course we can help with the specifics, but in order to believe in this new approach you will have to follow your own signature: learn something new every day. Don't be affraid this new approach will take too long. Its time lost is regained manyfold very very soon after. When I see the time span between your posts, the time you would have needed to learn the basics would already have been regained.

Re: How can I delete entire lines based on a search expression in vi?

Range Operators
Binary ".." is the range operator, which is really two different
operators depending on the context. In list context, it returns a list
of values counting (up by ones) from the left value to the right value.
If the left value is greater than the right value then it returns the
empty list. The range operator is useful for writing "foreach (1..10)"
loops and for doing slice operations on arrays. In the current
implementation, no temporary array is created when the range operator
is used as the expression in "foreach" loops, but older versions of
Perl might burn a lot of memory when you write something like this:
for (1 .. 1_000_000) {
# code
}
The range operator also works on strings, using the magical auto-
increment, see below.
In scalar context, ".." returns a boolean value. The operator is
bistable, like a flip-flop, and emulates the line-range (comma)
operator of sed, awk, and various editors. Each ".." operator
maintains its own boolean state. It is false as long as its left
operand is false. Once the left operand is true, the range operator
stays true until the right operand is true, AFTER which the range
operator becomes false again. It doesn't become false till the next
time the range operator is evaluated. It can test the right operand
and become false on the same evaluation it became true (as in awk), but
it still returns true once. If you don't want it to test the right
operand till the next evaluation, as in sed, just use three dots
("...") instead of two. In all other regards, "..." behaves just like
".." does.