Skip to content

Instantly share code, notes, and snippets.

@netologist
Created April 16, 2025 14:05
Show Gist options
  • Save netologist/9f68a2d29a2ec51f07bb05df3c712d4d to your computer and use it in GitHub Desktop.
Save netologist/9f68a2d29a2ec51f07bb05df3c712d4d to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check arguments
if [ $# -lt 1 ]; then
echo "Usage: $0 <filename>"
exit 1
fi
FILE="$1"
# Make a backup first
cp "$FILE" "$FILE.bak"
# Replace {{{VAR}}} and {{VAR}} with $VAR (any variable name)
perl -pe 's/\{\{\{\s*(\w+)\s*\}\}\}/\$$1/g; s/\{\{\s*(\w+)\s*\}\}/\$$1/g' "$FILE.bak" > "$FILE"
echo "Replacements complete. Backup saved as $FILE.bak"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment