"OneLiner" - replacement

Hi,

i have some replacement’s and would like to use the “in place
operator”.
How is it possible doing more than one repalcement, i thought i read
something
to hang the gsub method one after another, but it dosn’t work!?

ruby -pi*.bak -e ‘gsub(/VAR_TYP/,“TYP”).gsub(/VAR_FREQ/,“FREQ”)’
file.dat

many thanks
Christian

Christian Schulz wrote:

ruby -pi*.bak -e ‘gsub(/VAR_TYP/,“TYP”).gsub(/VAR_FREQ/,“FREQ”)’
file.dat

You don’t want the ‘*’ after the ‘i’ flag (I suspect).

Replace the ‘.’ by a ‘;’ between the two calls to gsub or replace the
two calls to gsub by calls to gsub! (keeping your ‘.’) and you should be
ok.

Note also that both your substitutions are doing the same thing
(removing VAR_) so you can do it in one:

ruby -pi.bak -e 'gsub /VAR_(TYP|FREQ)/, “\1” ’ file.dat

(The double backslash here is required because of the use of double
quotes. To avoid that, put the quotes the other way round:

ruby -pi.bak -e "gsub /VAR_(TYP|FREQ)/, ‘\1’ " file.dat

Mark B. wrote:

Replace the ‘.’ by a ‘;’ between the two calls to gsub or replace the
two calls to gsub by calls to gsub! (keeping your ‘.’) and you should be
ok.

Actually, forget chaining the calls to gsub! as you’ll bomb if no sub is
made. Sorry.

Just use separate call to gsub rather than chaining them.

First, I don’t think the * is doing what you think it is. ‘ruby -
pi.bak’ is probably what you want. Second, it’s more efficient to use
one regex when you don’t really need two.

ruby -pi.bak -e ‘gsub(/VAR_(TYP|FREQ)/,’\1’)’ file.dat

On 25 Feb., 17:01, Mark T. [email protected] wrote:

First, I don’t think the * is doing what you think it is. ‘ruby -
pi.bak’ is probably what you want. Second, it’s more efficient to use
one regex when you don’t really need two.

ruby -pi.bak -e ‘gsub(/VAR_(TYP|FREQ)/,’\1’)’ file.dat

many thanks’s , it’s too bad but i have a lot of replacment’s
difficult to combine.
The hint for “;” instead of “.” is my solution and now i recognize why
my replaced file end with $$$ instead of *.bak
like in perl.

regards, Christian