I'm know I could have done this by hand way faster than it took me to figure out.

I’m sure there are better ways to do this than I figured out below.

But still enjoyed figuring it out.

Scenario:
Uninstall all gems with version 3.0.0.beta4. These map to one of the last Rails 3 betas.
…and do it in one bash command.

This is what I ended up with.

gem list | grep beta4 | awk '{print $1}' | xargs gem uninstall -v=3.0.0.beta4

  • gem list – lists all installed gems
  • grep beta4 – filters the output to lines containing ‘beta4’
  • awk ‘{print $1'}’ – takes each line and outputs only the gem name (not the version info)
  • xargs – takes the last output and appends it to the given command: gem uninstall -v=3.0.0.beta4

Cool, huh?

Well, if you know bash, maybe not. I’d love to see a “better” version of this.