Unix/Linux Go Back    


Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

How to replace special characters in vi?

Solaris


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 08-02-2011   -   Original Discussion by rogerben
rogerben's Unix or Linux Image
rogerben rogerben is offline
Users Awaiting Email Confirmation
 
Join Date: Jan 2009
Last Activity: 2 March 2018, 8:11 AM EST
Location: India
Posts: 126
Thanks: 12
Thanked 0 Times in 0 Posts
How to replace special characters in vi?

Hi ,
I want to replace the special characters in the file.
For eg: cat abc
1234/4455/acb
234/k/lll/
234`fs`fd

I want to replace / and ` with the letter a and the output should like below. How to achieve this.
1234a4455aacb
234akallla
234afsafd
Sponsored Links
    #2  
Old Unix and Linux 08-02-2011   -   Original Discussion by rogerben
yazu's Unix or Linux Image
yazu yazu is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 2 August 2017, 9:27 AM EDT
Location: From far
Posts: 1,000
Thanks: 21
Thanked 237 Times in 231 Posts
Try:


Code:
:%s!/!a!g
:%s/`/a/g

"/" and "`" are not special in regular expressions. And you can use almost any non alphanum char as a separator for patterns in "s" command.
Sponsored Links
    #3  
Old Unix and Linux 08-03-2011   -   Original Discussion by rogerben
vivek.goel.piet's Unix or Linux Image
vivek.goel.piet vivek.goel.piet is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 19 December 2013, 1:41 AM EST
Posts: 72
Thanks: 12
Thanked 3 Times in 3 Posts
Bingo!!

Correct answer dude!!!
Quote:
Originally Posted by yazu View Post
Try:


Code:
:%s!/!a!g
:%s/`/a/g

"/" and "`" are not special in regular expressions. And you can use almost any non alphanum char as a separator for patterns in "s" command.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace new line with <br /> & escape special characters ted_chou12 Shell Programming and Scripting 2 02-07-2011 08:25 PM
Using sed to replace special characters nimo Shell Programming and Scripting 5 08-12-2010 02:42 AM
Find and replace special characters in a file sujithchandra UNIX for Dummies Questions & Answers 2 10-24-2008 06:59 AM
Help with find and replace w/string containing special characters CAGIRL UNIX for Dummies Questions & Answers 4 10-07-2008 07:13 PM
Replace Special characters in a file solai UNIX for Dummies Questions & Answers 1 07-13-2006 10:36 AM



All times are GMT -4. The time now is 05:19 AM.