Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace Pathnames in VI

Status
Not open for further replies.

KnowNix

MIS
Nov 10, 2003
32
NL
I want to replace every occurrence of a PATHNAME in a script with VI.
For example :

replace all occurence of : /usr/local/bin into /home/userx

I can't do it with VI's command :s/oldstring/newstring

Any suggestions would be great.
Thanks. Peer.
 
You have to escape the / in the pathname. Try this:

:%s/\/usr\/local\/bin/\/home\/userx/g
 
or...
:%s#/usr/local/bin#/home/user#g

IBM Certified -- AIX 4.3 Obfuscation
 
Thanks both for you answer. Sorry bi, but I prefer the option of Yegolev, because for me it's easier to read and remember.

p.s.
Thanks to all people on this forum, for helping 'AIX-beginners' like me, I will follow this forum everyday !
 
Yes. Yegolev's solution is less messy. But don't forget about using \ to escape a / or other characters. You may need it in the future when # doesn't work for a particular scripting scenario.
 
you may also use these as delimiters

: ^ ! $ @ * - _ + =

for example
:%s=/usr/local/bin=/home/user=g

tested in standard vi which comes with AIX 5100-04.

IBM Certified -- AIX 4.3 Obfuscation
 
I added the comment about using \ to escape characters when escape characters (delimiters?) don't work "for a particular scripting scenario" -- for example, is you are using sed or awk in a script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top