fork download
  1. #!/bin/bash
  2. s="some KEY- text
  3. some text @@some-text-KEY-some-other-text@@
  4. text again @@some-text-KEY-some-other-text@@ not this KEY- here @@some-text-KEY-some-other-text@@
  5. again @@some-text-KEY-some-other-text-KEY-text@@
  6. some text with KEY @@KEY-some-text@@
  7. blabla @@KEY@@"
  8.  
  9. perl -pe 's/(@@)(.*?)(@@)/$end_delim=$3; "$1" . $2=~s|KEY-|VALUE-|gr . "$end_delim"/ge' <<< "$s"
Success #stdin #stdout 0s 4972KB
stdin
Standard input is empty
stdout
some KEY- text
some text @@some-text-VALUE-some-other-text@@
text again @@some-text-VALUE-some-other-text@@  not this KEY- here @@some-text-VALUE-some-other-text@@
again @@some-text-VALUE-some-other-text-VALUE-text@@
some text with KEY @@VALUE-some-text@@
blabla @@KEY@@