Skip to content

Instantly share code, notes, and snippets.

@dvejmz dvejmz/addline.sh
Created Jul 3, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.