se a solução não estiver limitada a sed
, então awk
é seu amigo, com o seguinte oneliner:
awk 'BEGIN{file="NewText.txt";}{if(/SOMETEX/) count++; if(count==2){while((getline<file)>0) {print};count++;} else print;}' OldText.txt > new.txt
O que faz:
awk 'BEGIN{file="NewText.txt";} #sets the path to the
file that will be inserted
{if(/SOMETEX/) count++; #counts occurences of SOMETEX (regex-matching)
if(count==2) #if we just found the second occurence then
{while((getline<file)>0) {print};count++;} #read all lines of
file and print them
else print; #otherwise just print the line
}'