perl -e '$/="text1"; <>; $/="text2"; $_=<>; chomp; print "$_\n";' < file