Sed

 

  1. 全词替换
    echo bar embarassment | sed 's/\bbar\b/BAR/g'
    echo bar embarassment | sed 's/\<bar\>/BAR/g'

     

  2. -i.bak 替换的同时备份原文件

     

     

    1 Unix unix unix 23
    2 linux Linux 34
    3 linuxunix UnixLinux
    linux /bin/bash CentOS Linux OS
    Linux is free and opensource operating system

     

  3. sed 's/search_string/replacement_string/2' sample
    替换第二个



    简单用法示例:https://linux.cn/article-11367-1.html

     

  4.  行首或行尾添加内容

    sed -i.bak '/^[[:lower:]]/ s#^#HEAD&#g' sample
    sed -i.bak '/^[[:digit:]]/ s#^#&TAIL#g' sample
    sed -i.bak '/./ s#^#HEAD&#;s#$#&TAIL#' sample

     

  5. 删除'\r'
    sed -i 's/\r//g' sample

     

  6.  分组提取

     echo "background-image: url(/media/images/index/im2.jpg);"|sed -nr 's|^.*url\((.+)\).*$|\1|p'

     

  7. IGNORECASE

     

     

     

     

     

posted @ 2020-09-27 14:06  ascertain  阅读(121)  评论(0编辑  收藏  举报