Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using Linux Red Hat 5 Enterprise version. When using vi to replace string, we normally use the following command in vi -- "s/original_word/replaced_word/g", my question is, if original_word or replaced_word contains "/", how to replace?

For example, I want to replace /goo/foo/zoo to /1/2/3.

thanks in advance!

share|improve this question

2 Answers 2

up vote 3 down vote accepted
  1. you can use a different separator, eg : or , or ; or | or whatever you like
  2. escape the separator if the separator is part of the search string, meaning: put a \ before the separator, like this s/goo\/foo\/zoo/1\/2\/3/g
share|improve this answer
    
Thanks, question answered! –  George2 Jul 28 '10 at 12:47

Either use a different character for the command delimiter, or escape the slashes.

:s!/foo!/bar!
:s/\/foo/\/bar/
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.