sed Find and Replace Text Between Two Strings or Words

I am looking for a sed in which I can recognize all of the text in between two indicators and then replace it with a place holder.

For instance, the 1st indicator is a list of words

"no|noone|havent"

and the 2nd indicator is a list of punctuation

 ".|,|!".

From a sentence such as

"noone understands me."

I want to recognize "understands me" and add an affix onto the end of each word, desired result being

"noone understands_AFFIX me_AFFIX."

.

I know that there is the sed:

sed -n '/WORD1/,/WORD2/p' /path/to/file

which recognizes the content between two indicators, but I am not able to adapt it properly to accurately and efficiently solve my specific issue. Does anyone have a suggestion?

Where has your second indicator gone in the result?
I don't think you can do that with sed , but e.g. awk would lend itself to solve your ptoblem.

Sorry @RudiC when I was writing the question, I forgot to include it when copying and pasting.

I was not aware that this could be done with awk . How would you suggest attacking this problem using that?

Given that

  • indicator 1 & 2 arein line 1 & 2 of file1
  • the indicator2 (= period in this sample) is a word of its own in file2
    you can try
awk '
NR==1   {for (n=split($0, T, "|"); n>0; n--) S1[T[n]]
         next
        }
NR==2   {for (n=split($0, T, "|"); n>0; n--) S2[T[n]]
         next
        }
        {for (i=1; i<=NF; i++)  {if ($i in S1)  {L = 1
                                                 continue
                                                }
                                 if ($i in S2)   L = 0
                                 if (L)  $i = $i "_AFFIX"
                                }
        }
1
' file1 file2
noone understands_AFFIX me_AFFIX .