Find and replace text with all-inclusive wild card
问题 I have a file like this: foo and more stuff various stuff variable number of lines with a bar Stuff I want to keep More stuff I want to Keep These line breaks are important I want to replace everything between foo and bar so that I get: foo testtext bar Stuff I want to keep More stuff I want to Keep These line breaks are important as recommended in another thread I tried: sed -e '/^foo/,/^bar/{/^foo/b;/^bar/{i testtext' -e 'b};d}' file.txt Is there a more general-purpose solution to find and