Skip to content

Instantly share code, notes, and snippets.

@innermond
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save innermond/a5046ffc6aacfea858df to your computer and use it in GitHub Desktop.

Select an option

Save innermond/a5046ffc6aacfea858df to your computer and use it in GitHub Desktop.
Insert lines into certain files. After first and before last line
#!/bin/bash
# insert text lines after first line and before last line of file
# $1 = a glob expression like */assets/*.css
# $2 = a literal to be inserted after first line
# $3 = same as above but inserted before last line
for f in $1; do
eval "sed -ri '1 s/(.*)/\1\n$2; $ s/(.*)/$3\n\1/' \"$f\""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment