sed why POSIX blacket expression needs to be in another blacket?

问题内容:

Qustion

What is the reason that POSIX expression such as [:space:] needs to be in another [ ] ?

$ echo "a b c" | sed 's/[:space:]*/_/g'
_ _b_ _

$ echo "a b c" | sed 's/[[:space:]]*/_/g'
_a_b_c_

$ echo "a b c" | sed 's/[[:space:]][[:space:]]*/_/g'
a_b_c

问题评论:

    
inside single [] the :space: is equivalent to [:aceps].. also, what if you need to other characters? for ex: echo 'a b c?d' | sed 's/[[:space:]?]/_/g'

原文地址:

https://stackoverflow.com/questions/47750436/sed-why-posix-blacket-expression-needs-to-be-in-another-blacket

Tags:, ,

添加评论

友情链接:蝴蝶教程