# If you'd like to omit non-matching lines from the result; add ';d' to the end of the expression.
sed -E 's/^NoticeText:(?:(?!\nNoticeText:)[\s\S])*\n\s+Text\s*\[str\]\s*=\s*"([^"]*)"(?:(?!\nNoticeText:)[\s\S])*/$1/gmix;t' <<< "NoticeText:
NoticeType [str] = USER_TYPING_ON
Text [str] = \"user is typing\"
EventInfo:
PartyId [int] = 2
EventType [str] = MESSAGE
UserNickname [str] = \"Michael\"
EventId [int] = 4
Text [str] = \"Hey, how are you?\"
MsgCheck [str] = NONE
TimeOffset [int] = 23
UserType [str] = AGENT
NoticeText:
NoticeType [str] = USER_TYPING_ON
EventInfo:
PartyId [int] = 1
EventType [str] = MESSAGE
UserNickname [str] = \"Bob Smith\"
EventId [int] = 6
Text [str] = \"I'm good, how are you?\"
MsgCheck [str] = NONE
TimeOffset [int] = 28
UserType [str] = CLIENT
MessageType [str] = \"text\""
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for SED, please visit: https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html