|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 -- Posted via http://www.ruby-forum.com/. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Mark Bush 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. -- Posted via http://www.ruby-forum.com/. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 25 Feb., 17:01, Mark Thomas <m...@thomaszone.com> 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 |
|
![]() |
| Outils de la discussion | |
|
|