Sunday, January 06, 2008

Use Ruby language power in command line

Task: Delete file that didn't added to subversion

svn st|grep ?

Then you can get all the files that not added to subversion but the list is with a ?, so It's not easy to delete it with rm

felix@Felix:~/Developments/joblet$ svn st|grep ?
?      aaa
?      bbb
?      ccc

Then I want to trim the ?, awk may simple do the task, but for those who don't know awk. and instead we use Ruby for day to day work.

Ruby gives you the way to do task on command line.

 felix@Felix:~/Developments/joblet$ svn st|grep ?|ruby -pe '$_ = $_[1..-1].strip + "\n"'
 aaa
 bbb
 ccc

felix@Felix:~/Developments/joblet$ rm `svn st|grep ?|ruby -pe '$_ = $_[1..-1].strip + "\n"'`