zoukankan      html  css  js  c++  java
  • sed

    测试文本内容:

    This is a Certificate Request file:

    It should be mailed to zawu@seu.edu.cn

    =========================================================
    Certificate Subject:

    /O=Grid/OU=GlobusTest/OU=simpleCA-seugrid1.seu.edu.cn/OU=seu.edu.cn/CN=globus

    The above string is known as your user certificate subject,and it uniquely identifies this user, $88
    To install this user certificate,please save this e-mail into the following file.

    /home/globus/.globus/usercert.pem

    -n的使用

    定位

    匹配元字符

    如果sed命令匹配的目标字符串中包含元字符,需要使用转义符""屏蔽其特殊意义

    sed -n '/./p' input

    使用元字符进行匹配($符)

     $在正则中表示行尾,但是在sed命令中却表示最后一行

    sed -n '$p' input

    结果:

        /home/globus/.globus/usercert.pem

    编辑

    插入文本 /i

    直接引用行号

    sed '1i hello' input  #在第一行之前插入一行,内容为hello

    模式匹配之后

    sed '/file:/i hello' input #所有匹配file:的行之前,添加一行内容为hello

     *(行)后追加使用a,原理相同,下面举两例,后省略:

    sed '1a hello' input
    sed '/file:/a we add this line' input

    修改文本 /c

    使用c标记

    sed '/file:/c we edit this line' input  #此行相当于被覆盖重写

    删除文本

    单行:sed '1d' input

    多行:sed '1,3d' input

    替换文本

    s/被替换的文本/替换文本/替换选项

    替换之后再打印修改的行

    补充(与模式、或模式):

    同时匹配ABC 和 123:

    sed -n '/ABC/{/123/p}'        
    awk '/ABC/&&/123/{ print $0 }'  
    grep -E '(ABC.*123|123.*ABC)'    

    匹配ABC 或 123:

    sed -n '/(ABC|123)/p'
    awk '/ABC/||/123/{ print $0 }'
    grep -E '(ABC|123)'egrep 'ABC|123'

    样式:

    /(A|B|C|D|...)/p

  • 相关阅读:
    centos7 安装mysql
    ketlle windows下的安装(最基本)
    Spark参数详解 一(Spark1.6)
    SSM项目集成Lucene+IKAnalyzer在Junit单元测试中执行异常
    解决jquery.pjax加载后的异常滚动
    码云项目克隆至github
    JFinal获取多个model
    避免layui form表单重复触发submit绑定事件
    解决pjax重复绑定
    jfinal 拦截器中判断是否为pjax请求
  • 原文地址:https://www.cnblogs.com/tinaluo/p/15333616.html
Copyright © 2011-2022 走看看