I want to replace a string which contains "/" in vi but what is the escape character for forward slash?
e.g. I have a text file with the contents below and I want to replace "/Top/Sub/Sub1" with "ABC".
/Top/Sub/Sub1
The replace command I am using is %s/string_before_replace/string_after_replace/g.
%s/\/Top\/Sub\/Sub1/ABC/g
Cheers
ZB
Make life easy for yourself. The "/" in the search/replace command is just a default. How about this:
%s#/Top/Sub/Sub1#ABC#g
or
%s+/Top/Sub/Sub1+ABC+g
or
%s_/Top/Sub/Sub1_ABC_g
...etc... You get the idea. If you know you've got a lot of /'s, try to avoid all those \/'s. It's ugly and error-prone.
-mschwage
Neo
5
Great idea. I like the mschwage's suggestion. I used to use the \/ method, but now I will change to mschwage's default-changing method
Thanks for the contribution. I love it when I learn something new here on UNIX.COM!