Skip to content

Instantly share code, notes, and snippets.

@dvejmz
Created July 3, 2018 21:40
Show Gist options
  • Save dvejmz/5ab22fbec13a6cf34fde5644d6b587eb to your computer and use it in GitHub Desktop.
Save dvejmz/5ab22fbec13a6cf34fde5644d6b587eb to your computer and use it in GitHub Desktop.
Add an arbitrary block of text to a file
#!/bin/env bash
## Example usage:
## ../addline.sh 'matchtext' index.html
## find . -name "*.html" -exec ../addline.sh 'matchtext' '{}' \;
MATCH="${1}"
FILE="${2}"
INSERT=$(cat <<'EOF'
<text here>
EOF
)
sed -i "s@${MATCH}@${MATCH}\n${INSERT}@I" ${FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment