zhyiwww
用平实的笔,记录编程路上的点点滴滴………
posts - 536,comments - 394,trackbacks - 0
[1]在匹配内容的后面追加
    比如,想在文件中匹配 123(所有的三位数字) 的后面追加.html
    sed -n "s/[0-9]\{3\}/&\.html/p" *.log
[2]多次重复匹配
    重复n次以上
    sed -n "s/[0-9]\{3\}/&\.html/p" *.log
[3]替换内容中使用当前查找到的内容
    sed "s/password:/&mypassword/g" database.yml
    例如:
    替换前的内容

development:
  adapter: mysql
  encoding: utf8
  database: blog_development
  pool: 5
  username: root
  password:
  host: localhost


test:
  adapter: mysql
  encoding: utf8
  database: blog_test
  pool: 5
  username: root
  password:
  host: localhost

production:
  adapter: mysql
  encoding: utf8
  database: blog_production
  pool: 5
  username: root
  password:
  host: localhost

替换后的内容
development:
  adapter: mysql
  encoding: utf8
  database: blog_development
  pool: 5
  username: root
  password:mypassword
  host: localhost


test:
  adapter: mysql
  encoding: utf8
  database: blog_test
  pool: 5
  username: root
  password:mypassword
  host: localhost

production:
  adapter: mysql
  encoding: utf8
  database: blog_production
  pool: 5
  username: root
  password:mypassword
  host: localhost








|----------------------------------------------------------------------------------------|
                           版权声明  版权所有 @zhyiwww
            引用请注明来源 http://www.blogjava.net/zhyiwww   
|----------------------------------------------------------------------------------------|
posted on 2009-02-26 10:01 zhyiwww 阅读(253) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: