Created
July 3, 2018 21:40
-
-
Save dvejmz/5ab22fbec13a6cf34fde5644d6b587eb to your computer and use it in GitHub Desktop.
Add an arbitrary block of text to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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