Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pbrisbin
Created January 24, 2013 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrisbin/4627340 to your computer and use it in GitHub Desktop.
Save pbrisbin/4627340 to your computer and use it in GitHub Desktop.
# Note: I'm assuming GNU sed, this would need tweaking to run on OSX
# which I'm not inclined to research/test right now.
cat > Gemfile.example <<EOF
gem "awesome"
gem "lame"
EOF
echo -e "\nBefore:"
cat Gemfile.example
sed -i '/gem "lame"/d' Gemfile.example
echo -e "\nAfter"
cat Gemfile.example
# Or if you prefer generalized and reusable
remove_gem() {
sed -i -r "/gem\s+('|\")$1\1/d" "${2:-Gemfile}"
}
remove_gem lame Gemfile.example
@gstark
Copy link

gstark commented Jan 24, 2013

I believe the OS X version requires an extension parameter supplied to -i (.bak or similar)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment