Skip to main content
1 of 3
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k

If you want to use sed, you can read from a named pipe:

tmp=$(mktemp -d)
(
  cd "$tmp"
  mkfifo dynamic
  wget -O dynamic "$CONTENT" & wget_pid=$!
  sed -e '/^# BEGIN DYNAMIC BLOCK - DO NOT EDIT MANUALLY$/ p' \
      -e '/^# END DYNAMIC BLOCK$/ {' -e p -e 'r dynamic' -e '}' \
      -e '/^# BEGIN DYNAMIC BLOCK - DO NOT EDIT MANUALLY$/, /^# END DYNAMIC BLOCK$/ d'
  kill $wget_pid
)
rm -rf "$tmp"

But I'd go for awk.

export CONTENT
awk '
    $0 == "# BEGIN DYNAMIC BLOCK - DO NOT EDIT MANUALLY" {skip=1; next}
    $0 == "# END DYNAMIC BLOCK" {skip=0; system("wget $CONTENT")}
    !skip {print}
'
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k