Nikolaos A. Patsopoulos wrote:
Yakov Lerner wrote:
On 9/14/06, Nikolaos A. Patsopoulos <[EMAIL PROTECTED]> wrote:
Yakov Lerner wrote:
> On 9/14/06, Nikolaos A. Patsopoulos <[EMAIL PROTECTED]> wrote:
>> Yakov Lerner wrote:
>> > On 9/14/06, Nikolaos A. Patsopoulos <[EMAIL PROTECTED]> wrote:
>> >> 2.Can I delete after a pattern search? Sth like this:
>> >>
>> >> :/^<html\_.{-}<body>: /-3d
>> >>
>> >> and how can I repeat this globally?
>> >
>> > :g/^<html\_.{-}<body>: /.-3d
>> >
>> > Yakov
>> >
>> >
>> I get an E16: invalid range error
>
> Yeah, this can happen if pattern is found
> in line number < 4. (Then .-3 results in <=0 which is invalid
> line number). Just insert 4 dummy empty lines
> at beginning of file to avoid this.
>
> Yakov
>
>
This means that the -3d counts from the beginning of the pattern?? In my
file The first occurrence of the patten expands from line 1 to line 82.

Yes, from the beginning of the pattern

Yakov


How can I force it to delete 3 lines from the end?


Disclaimer: Everything below is untested.

Normally, an HTML page should have only one <BODY> tag. The following should do (without :g)

        :1|/\c<body\>/-3d

If you may have, before <HTML>, a <BODY> which mustn't trigger a deletion:

        :1|/\c<\@<=html\>/;/\c<body\>/-3d

If (your original command) you may have several <HTML> tags in a single file, and the single line 3 lines above the next <BODY> tag must be deleted... well, I think it's doable but I won't venture a command.

Note: \c in a pattern means "disregard case", \> means "end-of-word", x\@<= means "if preceded by x". The latter is used here (in the second example) to avoid missing <HTML> at the start of line 1.


Best regards,
Tony.

Reply via email to