Chinaunix

标题: 如何用sed只匹配第一次 [打印本页]

作者: zhao3stones    时间: 2009-08-19 18:50
标题: 如何用sed只匹配第一次
ie:  xxxx[yyyy]sssss[2222]

output: xxxxsssss[2222]

就是只删除第一次[]内的内容, 请用sed
作者: __lxmxn__    时间: 2009-08-19 19:03
sed -e 's/\[[^]]*\]//'
作者: ubuntuer    时间: 2009-08-19 19:29
  1. echo "xxxx[yyyy]sssss[2222]" | sed 's/\[[^]]*\]//'
复制代码

作者: blackold    时间: 2009-08-19 19:29
"默认"就是只做一次啊。
作者: zhao3stones    时间: 2009-08-19 19:44
哇,谢谢
作者: zhao3stones    时间: 2009-08-19 20:14
原帖由 blackold 于 2009-8-19 19:29 发表
"默认"就是只做一次啊。


哈哈哈哈
作者: Shell_HAT    时间: 2009-08-19 23:11
sed1line
http://bbs.chinaunix.net/viewthread.php?tid=325187
# substitute (find and replace) "foo" with "bar" on each line
sed 's/foo/bar/'             # replaces only 1st instance in a line
sed 's/foo/bar/4'            # replaces only 4th instance in a line
sed 's/foo/bar/g'            # replaces ALL instances in a line
sed 's/\(.*\)foo\(.*foo\)/\1bar\2/' # replace the next-to-last case
sed 's/\(.*\)foo/\1bar/'            # replace only the last case





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2