Re: Newb: Search & Replace



On Sat, 31 Dec 2005, Robert Klemme wrote:

> Wybo Dekker <wybo@xxxxxxxxxxx> wrote:
> > On Sat, 31 Dec 2005, Art Gillespie wrote:
> >
> > > #!/usr/bin/env ruby
> > >
> > > VERSION_HEX=ARGV[0]
> > >
> > > File.open("iDrum_prefix.h.tmp", "w") do |ofile|
> > > File.open("iDrum_prefix.h") do |file|
> > > file.each do |line|
> > > if line =~ /^#define kIDComponentVersion\t*(.*)/
> > > ofile.puts line.sub($1, "#{VERSION_HEX}")
> > > else
> > > ofile.puts line
> > > end
> > > end
> > > end
> > > end
> > >
> > > File.rename("iDrum_prefix.h.tmp", "iDrum_prefix.h")
> >
> > with rio, you can edit a file inplace;
> > this changes all x into y in file z:
> >
> > #!/usr/bin/ruby
> > require 'rubygems'
> > require 'rio'
> > rio('z') < rio('z').read.gsub(/x/,'y')
>
> Um, rio is not needed:
>
> Robert@Babelfish2 /c/TEMP
> $ echo 'x' > iDrum_prefix.h
>
> Robert@Babelfish2 /c/TEMP
> $ cat iDrum_prefix.h
> x
>
> Robert@Babelfish2 /c/TEMP
> $ ruby -i.tmp -pe "gsub /x/, 'y'" iDrum_prefix.h
>
> Robert@Babelfish2 /c/TEMP
> $ cat iDrum_prefix.h
> y
>
> :-))
>
> robert

Uhm... ruby is not needed:

sed -ie 's/x/y/g' iDrum_prefix.h

But I suppose that Art Gillespie wanted to arrange things from a Ruby
script, where he does other things as well... Happy New Year!

--
Wybo


.



Relevant Pages

  • Re: concept of self
    ... On Wed, 6 Jun 2007, Robert Klemme wrote: ... the concept of 'self' in Ruby. ... That's quite a few years ago now and OOP has become my second nature - that's probably the reason why I did not find anything strange about "self". ... I didn't want to question the explanation, I was just curious whether I missed something. ...
    (comp.lang.ruby)
  • Re: Tree structure - how do we link nodes together?
    ... Robert Klemme wrote: ... Ruby does not have the multitude of options that C++ has. ... It helps me to think of references and the objects they point to as ... altered or corrupted during transmission. ...
    (comp.lang.ruby)
  • Re: Scraping off a Word document?
    ... Robert Klemme wrote: ... collide with RTF meta sequences). ... Now you only need to read in the mail template file from ... Ruby, do all the replacements and then write it out in Ruby again once ...
    (comp.lang.ruby)
  • Re: Multiple HTTP Sockets or Threads for file uploads.
    ... On Tue, Jun 24, 2008 at 11:06 AM, Robert Klemme ... and Curl to upload files to his file server (to and from Windows ... You just need to fork multiple curl processes. ... If you were doing it in pure Ruby you could use threads. ...
    (comp.lang.ruby)
  • Re: A couple of questions regarding class design
    ... Robert Klemme wrote: ... will make an entry and depending on what they enter the program will ... continue or jump to a totally different area. ... Now Michael just needs to integrate the Ruby interpreter into his Business Basic engine. ...
    (comp.lang.ruby)