Reputation: 67
I have a file containing below text for example:
the brown fox
the red fox
the brown cat
I want to replace "brown" with "yellow" and add "edited" at the end of line so that content of the file would be:
the yellow fox edited
the red fox
the yellow cat edited
Please tell me the solution!
Thanks for your help.
Upvotes: 1
Views: 1419
Reputation: 91518
\bbrown\b(.+)$
yellow$1 edited
. matches newline
Explanation:
\bbrown\b # literally brown surround with word boundaries to avoid matching "brownies" or "whateverbrown"
(.+) # group 1, 1 or more any character but newline
$ # end of line
Replacement:
yellow # literally
$1 # content of group 1 (every thing after brown) followed by a space
edited # literally
Screen capture (before):
Screen capture (after):
Upvotes: 3
Reputation: 5859
This will need to be done in two steps:
Ctrl + H
First step: using regex (make sure "Regular expression" is toggled in Search Mode below), find if sentence contains brown and append edited to end of sentence:
the brown fox edited
the red fox
the brown cat edited
Second step is easy - replace brown with yellow.
the yellow fox edited
the red fox
the yellow cat edited
Upvotes: 2