lidia
lidia

Reputation: 3183

sed - substitute either of two characters with one command

I would like one sed command to accomplish the following:

$ sed s'/:/ /g' <and> sed s'/=/ /g'

That is, I would like to write

sed s'/<something>/ /g' 

and have both = and : replaced by space.

Upvotes: 22

Views: 39331

Answers (3)

Strapakowsky
Strapakowsky

Reputation: 2343

Sanjay's answer solves it. Another option that works with only one sed command is to separate each s substitution with a semicolon

sed 's/:/ /g ; s/=/ /g' file

or in separate lines in a script

sed 's/:/ /g 
     s/=/ /g' file

Those may be handy in other situations.

Upvotes: 6

Anders
Anders

Reputation: 6218

One option is also to use sed -e, like this. Although you don't need it in this case, it's however a good option to know about.

sed -e 's/:/ /' -e 's/..../ /' file

Upvotes: 10

Sanjay Manohar
Sanjay Manohar

Reputation: 7026

sed s'/[:=]/ /g'

Brackets mean "any one of".

Upvotes: 43

Related Questions