开发者

sed - substitute either of two characters with one command

开发者 https://www.devze.com 2023-01-09 01:54 出处:网络
I would like one sed command to accomplish the following: $ sed s\'/:/ /g\' <and> sed s\'/=/ /g\'

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 spac开发者_开发百科e.


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

Brackets mean "any one of".


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号