1

I have a file which has multiple entries like this:

Abcd:abcd:*sometext*:klm:xyz/abc
Abcd:abcd:R%fs90uw:klm:xyz/abc

Now, I want to replace "klm" with "qrs" for only those lines which have the "sometext" string in the line.

How can I do this using the search and replace feature in vim?

Thanks!

2 Answers 2

4

:g is your friend:

:g/sometext/s/klm/qrs/g
Sign up to request clarification or add additional context in comments.

2 Comments

How about change entries only when sometext is NOT present?
I got that. It should be :v.
0

Also a substitution command can do the job:

:%s/\(sometext.*\)klm/\1qrs/g

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.