K_TGTK
K_TGTK

Reputation: 815

Replace end of line for lines that start with a particular pattern

I have a file in the following format

--Some-XYZ-code ;
--Somemore--xyz--code;
COMMENT = " THIS IS A DEMO"
--somemore--code;
--somemore--code;

I want to put an semicolon at the end of line COMMENT, keeping the rest of the line intact.

Upvotes: 4

Views: 294

Answers (3)

Birei
Birei

Reputation: 36252

Try this:

:g/^COMMENT/ normal A;

For every line that matches COMMENT at the beginning enter in Insert Mode at the end of the line and append a semicolon.

Explanation: :g selects every line that matches following pattern ^COMMENT and does the action after last slash, normal A;

Upvotes: 8

jaypal singh
jaypal singh

Reputation: 77075

This should work

:%s/^COMMENT.*/&;/

Upvotes: 4

Amadan
Amadan

Reputation: 198314

This should do it:

:g/COMMENT/norm A;

g: globally on all lines matching /COMMENT/,
norm: execute normal command
A;: of appending a semicolon to the end of the line.

Upvotes: 4

Related Questions