Stef
Stef

Reputation: 623

Multiline regex replacement in sed/vi

I need to replace this statement in a named.conf with regex

masters {
        10.11.2.1;
        10.11.2.2;
};

All my approaches with sed/vi do not work

%s/masters.*\}\;//g 

does not match. Also tried with /s \s etc to match the newline.

Upvotes: 1

Views: 470

Answers (1)

schesis
schesis

Reputation: 59238

In vim, you can force a pattern to match across newlines with \_, for example:

%s/masters {\_[^}]*};//g

It's important to replace .* with something more conservative like [^}]* if you prefix with \_, because * is greedy, so \_.* will try to match everything to the end of the document.

Upvotes: 1

Related Questions