The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Minicom runscript: How to send escape character ( \ ) rkhanna Shell Programming and Scripting 1 10-02-2008 11:14 AM
read a variable character by character, substitute characters with something else vipervenom25 UNIX for Dummies Questions & Answers 2 06-06-2008 04:18 PM
Escape character deepakpv Shell Programming and Scripting 4 02-16-2007 03:19 AM
awk / escape character OFFSIHR Shell Programming and Scripting 8 11-29-2006 01:28 PM
possible to escape the \ character in sed? gammaman UNIX for Dummies Questions & Answers 1 07-07-2005 03:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-16-2005
stevefox stevefox is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 115
Question Escape character in vi?

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.
  #2 (permalink)  
Old 11-16-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
%s/\/Top\/Sub\/Sub1/ABC/g

Cheers
ZB
  #3 (permalink)  
Old 11-16-2005
stevefox stevefox is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 115
Thanks zazzybob!
  #4 (permalink)  
Old 11-16-2005
mschwage mschwage is offline
Registered User
  
 

Join Date: Jul 2005
Location: Oak Park, IL
Posts: 102
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
  #5 (permalink)  
Old 11-17-2005
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,746
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!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0