vi search & replace ... having '/' in string - problem. | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

vi search & replace ... having '/' in string - problem.

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-20-2007
videsh77 videsh77 is offline
Registered User
 
Join Date: Aug 2004
Last Activity: 22 April 2014, 2:17 PM EDT
Posts: 151
Thanks: 0
Thanked 0 Times in 0 Posts
vi search & replace ... having '/' in string - problem.

I want to carry out search & replace for the paths mentioned in the file with the help of vi.

'abc/' to be replaced by 'abc/data'

When I use command in vi as below -

%s/abc//abc/data/g

it gives me an error.

How we should deal with '/' part in string for vi search & replace?

Thanks in advance.
Sponsored Links
    #2  
Old 06-20-2007
kamitsin's Avatar
kamitsin kamitsin is offline
Users Awaiting Email Confirmation
 
Join Date: Nov 2006
Last Activity: 19 June 2012, 2:15 AM EDT
Location: /dev/null
Posts: 178
Thanks: 0
Thanked 1 Time in 1 Post

Code:
s/abc//abc\/data/g

Sponsored Links
    #3  
Old 06-20-2007
videsh77 videsh77 is offline
Registered User
 
Join Date: Aug 2004
Last Activity: 22 April 2014, 2:17 PM EDT
Posts: 151
Thanks: 0
Thanked 0 Times in 0 Posts
I am still getting error message as -

'There are extra characters at the end of substitute command'.
    #4  
Old 06-20-2007
kamitsin's Avatar
kamitsin kamitsin is offline
Users Awaiting Email Confirmation
 
Join Date: Nov 2006
Last Activity: 19 June 2012, 2:15 AM EDT
Location: /dev/null
Posts: 178
Thanks: 0
Thanked 1 Time in 1 Post
Quote:
abc
abc
abc
abc
abc
~
~
:%s/abc/abc\/data/g
Output:

Quote:
abc/data
abc/data
abc/data
abc/data
abc/data
So i am not sure why it will not work on your system !!
Sponsored Links
    #5  
Old 06-20-2007
RishiPahuja's Avatar
RishiPahuja RishiPahuja is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 15 April 2011, 1:11 AM EDT
Location: Bangalore, India
Posts: 203
Thanks: 0
Thanked 0 Times in 0 Posts
Tools

Try this out

:%s/abc\//abc\/data/g
Sponsored Links
    #6  
Old 06-20-2007
videsh77 videsh77 is offline
Registered User
 
Join Date: Aug 2004
Last Activity: 22 April 2014, 2:17 PM EDT
Posts: 151
Thanks: 0
Thanked 0 Times in 0 Posts
Great Rishi, your command helped.
Sponsored Links
    #7  
Old 06-20-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 21 June 2012, 3:19 PM EDT
Location: Bahia, Brazil
Posts: 1,203
Thanks: 1
Thanked 103 Times in 100 Posts

Code:
:%s;abc/;abc/data;g

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk - replace number of string length from search and replace for a serialized array otrotipo Shell Programming and Scripting 1 07-10-2009 12:04 PM
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 9 06-08-2009 06:11 AM
Search for a string and replace the searched string in the same position in samefile ganesh_248 UNIX for Dummies Questions & Answers 27 03-23-2009 12:35 AM
Search for a string and replace the searched string in the same position ganesh_248 Shell Programming and Scripting 15 02-09-2009 08:35 PM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 09:24 AM



All times are GMT -4. The time now is 10:21 PM.