1848155 Members
8408 Online
104022 Solutions
New Discussion

Re: vi

 
SOLVED
Go to solution
Sanjiv Sharma_1
Honored Contributor

vi

Hi,

I have a text file "abc" in which I want to substitute all the "/users/tiger" to "/rain/blue/violet"

In the file abc "/users/tiger" exists about 100 times.

Thanks,
Raje.
Everything is possible
10 REPLIES 10
Sebastian Galeski_1
Trusted Contributor
Solution

Re: vi

Hi
%s;/users/tiger;/rain/blue/violet;g

regards seba
Michael Tully
Honored Contributor

Re: vi

Hi Raje,

To change all occurances of /users/tiger to /rain/blue/violet.

vi the file and then:

:1,$s/\/users\/tiger/\/rain\/blue\/violet/g

HTH
Michael
Anyone for a Mutiny ?
Sebastian Galeski_1
Trusted Contributor

Re: vi

Of course use this command in vi
Michael Tully
Honored Contributor

Re: vi

Or using sed from the command line

cat abc | sed 's/\users\/tiger/\rain\/blue\/violet/g' >abc.1
Anyone for a Mutiny ?
Robin Wakefield
Honored Contributor

Re: vi

Hi Raje,

Using perl:

perl -pi -e 's+/users/tiger+/rain/blue/violet+g' filename

Rgds, Robin
Justo Exposito
Esteemed Contributor

Re: vi

Hi Raje,

As Procura recommend is better not to use cat:
sed 's/\users\/tiger/\rain\/blue\/violet/g' abc >abc.1

If you want to check the changes you can use grep:

grep "\/users\/tiger" abc

Regards,

Justo.
Help is a Beatiful word
Trond Haugen
Honored Contributor

Re: vi

My suggestion is only slightly different from Michaels:

:g/\/users\/tiger/s//\/rain\/blue\/violet/g

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
harry d brown jr
Honored Contributor

Re: vi


1,s_/users/tiger_/rain/blue/violet_g9999


live free or die
harry
Live Free or Die
Judy Traynor
Valued Contributor

Re: vi

Here is the syntax for search/replace. (there are already a lot of winners here.
)

:g/search-string/s//replace-string/ global search and replace

Sail With the Wind
harry d brown jr
Honored Contributor

Re: vi


Monica,

I was pointing out that the separator does not have to be a slash (/), and that an underscore (_) can easily be used (as any other character also). The point being that too many forward and backward slashes is just insanely crazy.

live free or die
harry
Live Free or Die