Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinhooke/982891f622701ce70de8bef630fc9b9b to your computer and use it in GitHub Desktop.
Save kevinhooke/982891f622701ce70de8bef630fc9b9b to your computer and use it in GitHub Desktop.
bash prepend and append content to a number of matching files
#!/bin/bash
for f in $(find . -name "*.jsp")
do
echo "Updating file: $f"
#prepend: note BSD requires an empty '' param to sed -i
sed -i '' '1s/^/new line1\
new line2\
new line3\
/' $f
#append trailing content
echo "new line 4
new line5
new line6" >> $f
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment