开发者

Help! How do you s/// "[one] abc [two]" into "X abc X"?

My failed attempt:

s/\[[^\[\]]*\]/X/

No mat开发者_JS百科ch in ed or sed.

Thanks!


If you mean the literal string [one] abc [two] use e.g. this:

s/[[][^]]*]/X/g

It'll replace [ + anything not ] + ] with X.


The [brackets] literally? Or is the blank the significant part?

sed -r 's/(.*) (.*) (.*)/X \2 X/'

echo "[one] abc [two]" | sed -r 's/(.*) (.*) (.*)/X \2 X/'
X abc X


Ruby(1.9+)

$ echo "[one] abc [two]" | ruby -e 'print gets.gsub(/\[.*?\]/,"X") '
X abc X
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜