fork(1) download
  1. #!/bin/bash
  2. str="$(echo -e "abcde\n fghij<FooBar>")";
  3. echo "----- sed ------"
  4. sed 'H;1h;$!d;x; s/\(.*\)><Foobar>/\1/' <<< "$str"
  5. # Remove lines between two matching lines including them:
  6. sed '/^start;/,/^end;/d' <<< "$(echo -e "Here:\nstart;more text\nText... here\nend; and\nEnd of string.")"
  7. # Remove lines between two matching lines excluding them:
  8. sed '/^start;/,/^end;/{{//!d;};}' <<< "$(echo -e "Here:\nstart;more text\nText... here\nend; and\nEnd of string.")"
  9.  
  10. echo "----- Perl ------"
  11. perl -0pe 's/(.*)<FooBar>/$1/gs' <<< "$str"
  12.  
  13. echo "----- GNU grep ------"
  14. grep -Poz '(?si)abc\K.*?(?=<Foobar>)' <<< "$str"
Success #stdin #stdout 0s 19640KB
stdin
Standard input is empty
stdout
----- sed ------
abcde
		fghij<FooBar>
Here:
End of string.
Here:
start;more text
end; and
End of string.
----- Perl ------
abcde
		fghij
----- GNU grep ------
de
		fghij