Skip to content

Instantly share code, notes, and snippets.

@geekman
Created May 30, 2019 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geekman/ebf973adbd0141ac24fedee5c8aca955 to your computer and use it in GitHub Desktop.
Save geekman/ebf973adbd0141ac24fedee5c8aca955 to your computer and use it in GitHub Desktop.
replaces patterns like "<? cmd ?>" by executing cmd
#
# awk one-liner to replace patterns like "<? cmd ?>" by executing cmd
# handy for use in config files "templates"
#
cat <<EOF | awk '{ if (match($0, /<\?(.*)?>/)) { cmd = substr($0, RSTART+2, RLENGTH-2-2); system(cmd) } else print }'
my directory has these files:
<? ls / ?>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment