Re: Newb: Search & Replace
- From: Wybo Dekker <wybo@xxxxxxxxxxx>
- Date: Sat, 31 Dec 2005 22:56:02 +0900
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
.
- References:
- Newb: Search & Replace
- From: Art Gillespie
- Re: Newb: Search & Replace
- From: Wybo Dekker
- Re: Newb: Search & Replace
- From: Robert Klemme
- Newb: Search & Replace
- Prev by Date: Re: Is the Ruby executable written in C?
- Next by Date: Re: Medical APIs
- Previous by thread: Re: Newb: Search & Replace
- Next by thread: Re: Newb: Search & Replace
- Index(es):
Relevant Pages
|