Saturday, September 19, 2020

How to replace string in specific paragraph only?

Hi,
I have the following sample text file:

XXX ********  ****** ******
    ******* ***** ******
    *** aaa **** ****
    *** *** ******** **

YYY ********  ****** ******
    **** aaa *** *** ****
    ******* ***** ******
    *** *** ******** **

XXX ********  ****** ******
    * aaa *** **** ****
    ******* ***** ******
    *** *** ******** **

XXX ********  ****** ******
    *** *** ******** **
    * ** **** ***** ******
    aaa **** **** ***

ZZZ ********  ****** ******
    ****** **** **** aaa
    ******* ***** ******
    *** *** ******** **


with a lot more paragraphs.

REPLACE RULE:
I need to replace string "aaa" with "bbb" only in paragraphs that starts with "XXX".

ADDITIONAL INFO:
1. String "aaa" can be anywhere in the file (in paragraphs that do not start with "XXX").
2. Paragraphs are blocks of text separated with two new -ines characters.
3. Text is Unix like text (only new line character at the end of line to break a line).
4. There are no spaces or tabs at the end of line.
5. Paragraphs are always separated by two new-line characters, never more (like three or more).
6. There is no special order of "XXX" paragraphs inside file. "XXX" paragraphs appear randomly inside file.
7. The "XXX" string is at the beginning of line (no other character before it).

Regards

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/ba7b60e5-055b-4967-86ef-23886dbce972n%40googlegroups.com.

No comments:

Post a Comment