Mandar Pimplapure
Mandar Pimplapure

Reputation: 3

How to replace special character in Linux VI Editor?

I want to remove some special characters from a file in linux using vi editor, such as

{ 
}
:
[
] 

I tried below pattern but not working for all possible symbols above.

:%s/\{//g

got an error : E866: (NFA regexp) Misplaced { E64: { follows nothing E476: Invalid command

Upvotes: 0

Views: 925

Answers (1)

KamilCuk
KamilCuk

Reputation: 141930

Overall, see :h :s and :h pattern. See man 7 regex.

\{ starts a bound in basic regular expression. vi does not really use basic regular expression, but anyway, it's like close to it. You want to match character {, and not repeat previous pattern, so just match {.

:%s/{//g

for all possible symbols above.

If you want to put [ ] inside a bracket expression [...] you have to put them as the last/first. So like []] matches a single ], like [][] matches [ or ].

:%s/[]{}:[]//g

Upvotes: 1

Related Questions