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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replacing a nul field with text DarkHound Shell Programming and Scripting 3 09-04-2007 11:34 AM
Replacing text chrchcol Shell Programming and Scripting 3 07-25-2006 09:30 AM
replacing text ajaya Shell Programming and Scripting 2 04-12-2006 09:31 AM
Replacing text inside a directory vatsan UNIX for Advanced & Expert Users 1 03-31-2006 11:34 PM
replacing text in an ascii doc cubs0729 Shell Programming and Scripting 6 09-29-2005 12:05 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-25-2008
Registered User
 

Join Date: May 2007
Posts: 10
help required for replacing text in vi

Hi
Any one pls give me command in vi to replace /opt/usr with /home/reddy/dump .... i tried escaping / with \ bt its not working...


thanks in advance
Reply With Quote
Forum Sponsor
  #2  
Old 01-25-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
At the : prompt type

Code:
#/opt/usr#/home/reddy/dump#
Reply With Quote
  #3  
Old 01-25-2008
Registered User
 

Join Date: Mar 2007
Location: Somerset West, South Africa
Posts: 10
In vi:

:%s#\/opt\/usr#\/home\/reddy\/dump#g


QED! (quite easily done!)
Reply With Quote
  #4  
Old 01-25-2008
Registered User
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 99
:%s_/opt/usr_/home/reddy/dump_g

u can use anydelimiter ...since ur string cntains too many slashes, therefore to avoid escaping all the slashes and messy syntex... this 1 'll be the simplest.

Anchal.
Reply With Quote
  #5  
Old 01-25-2008
Registered User
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 99
@dewets : why u again esacpe the slashes... if u alreadyusing delim as "#".
i dont think its needed...
is there any other reason..... correct me if i m wrong...
Reply With Quote
  #6  
Old 01-25-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Quote:
Originally Posted by anchal_khare View Post
@dewets : why u again esacpe the slashes... if u alreadyusing delim as "#".
i dont think its needed...
is there any other reason..... correct me if i m wrong...
Yes, thats correct.

When '#' is used as delimiter no need to use '/' as '\/'

but using '#' when the patten contains '/' adds more readability
Reply With Quote
  #7  
Old 01-26-2008
Registered User
 

Join Date: Jul 2007
Location: India
Posts: 14
better use perl search and replace.

Quote:
perl -i -pe 's/old pattern/new pattern/g' filename
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0