• sed:在匹配模式的行首或者行尾插入字符


    info sed,可以看到更多

    https://www.onitroad.com/jc/misc/insert-character-in-the-beginning-or-end-of-line-with-matched-pattern-in-sed.html

    shannon:这个网站好像不错

    sed:在匹配模式的行首或者行尾插入字符

    示例文件“/tmp/file”

    1
    2
    3
    4
    5
    6
    7
    # Port rpc.statd should listen on.
    STATD_PORT=662
    Outgoing port statd should used. The default is port
    # is random
    STATD_OUTGOING_PORT=2016
    Specify callout program
    STATD_HA_CALLOUT="/usr/local/bin/foo"

    在行首添加内容

    示例1

    在包含“STATD#u PORT”的行开头添加“#”注释符号

    解决方案

    1
    2
    3
    4
    5
    6
    7
    8
    # sed '/STATD_PORT/s/^/#/' /tmp/file
    # Port rpc.statd should listen on.
    #STATD_PORT=662
    Outgoing port statd should used. The default is port
    # is random
    STATD_OUTGOING_PORT=2016
    Specify callout program
    STATD_HA_CALLOUT="/usr/local/bin/foo"

    将更改结果保存到文件:

    1
    # sed -i '/STATD_PORT/s/^/#/' /tmp/file

    示例 2

    要匹配的内容在行的中间

    匹配“callout”并在行首添加“#”注释字符

    解决方案

    1
    2
    3
    4
    5
    6
    7
    8
    # sed '/callout/s/^/#/' /tmp/file
    # Port rpc.statd should listen on.
    STATD_PORT=662
    Outgoing port statd should used. The default is port
    # is random
    STATD_OUTGOING_PORT=2016
    #Specify callout program
    STATD_HA_CALLOUT="/usr/local/bin/foo"

    在行尾添加内容

    示例 1

    在与“callout”匹配的行的末尾添加“your text”

    1
    2
    3
    4
    5
    6
    7
    8
    # sed '/callout/s/$/your text/' /tmp/file
    # Port rpc.statd should listen on.
    STATD_PORT=662
    Outgoing port statd should used. The default is port
    # is random
    STATD_OUTGOING_PORT=2016
    Specify callout program your text
    STATD_HA_CALLOUT="/usr/local/bin/foo"

    示例 2

    在以“STATD”开头的行的 末尾添加“your text”

    1
    2
    3
    4
    5
    6
    7
    8
    # sed '/^STATD/s/$/your text/' /tmp/file
    # Port rpc.statd should listen on.
    STATD_PORT=662 your text
    Outgoing port statd should used. The default is port
    # is random
    STATD_OUTGOING_PORT=2016 your text
    Specify callout program
    STATD_HA_CALLOUT="/usr/local/bin/foo" your text
  • 相关阅读:
    【NX二次开发】修改dlx对话框标题的方法
    【NX二次开发】导入x_t,UF_PS_import_data
    设置NX欢迎界面
    [转]10个顶级的CSS UI开源框架
    [转] 多线程 《深入浅出 Java Concurrency》目录
    [转] JAVA多线程和并发基础面试问答
    [转]StuQ 技能图谱(全套13张)
    [转] MongoDB shell 操作 (查询)
    搜集好的java技术帖子,持续更新,java程序员的要求
    [转]JAVA程序员一定知道的优秀第三方库(2016版)
  • 原文地址:https://www.cnblogs.com/e-shannon/p/15165055.html
Copyright © 2020-2023  润新知