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
精彩评论