How to delete all lines after line N that match "ABC"

Say I'm editing a file with 1000 lines.

I want to leave lines 1-500 intact.

But I want to delete all lines after line 500 that match "ABC"

How can i do this?

I can do all the lines on the line

:g/ABC/d 

And I can delete all rows in a range

 :501,$d 

But how to remove only lines matching the pattern?

(I have been using vi since 1989. I just can't think how to do this! Sorry if this is obvious)

+4
source share
1 answer

:global also accepts a range. So you want:

501,$g/ABC/d : -)

+13
source

Source: https://habr.com/ru/post/1498564/


All Articles