lsub

February 20th, 2007

#!/usr/bin/env ruby
pattern, replace = *ARGV
regexp = Regexp.new(pattern)
until $stdin.eof?
  line = $stdin.readline
  $stdout.print(line.sub(regexp, replace)) if line.match(regexp)
end
Which you might use this way:
#!/bin/bash
svn st | lsub "^\?\s+(.*)$" "\1"

1 Response to “lsub”

  1. Matthew Todd Says:
    Nice -- and thanks for the svnaddall reminder, Austin. I've been meaning to get around to that for some time now. An (admittedly perlish) alternative approach could lean on ruby's -n command-line option, that "assumes a while gets; ...; end loop around your program" : svn st | ruby -n -e 'puts $1 if /^\?\s+(.*)$/'

Sorry, comments are closed for this article.