Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
krisbai
V2EX  ›  Linux

如何截取文本内的对应字符串

  •  
  •   krisbai · Sep 18, 2017 · 1960 views
    This topic created in 3166 days ago, the information mentioned may be changed or developed.
    如题 。文本内的内容为:request_5xx:1792 total_count:21878634 request_4xx:552 total_request_time:469576
    假如想要 单独截取 request_4xx 对应的 552 改如何匹配呢?
    6 replies    2017-09-18 17:08:52 +08:00
    VShawn
        1
    VShawn  
       Sep 18, 2017
    正则表达式不行吗?
    Immortal
        2
    Immortal  
       Sep 18, 2017
    正则表达式不行吗?
    yiyiwa
        3
    yiyiwa  
       Sep 18, 2017
    echo request_5xx:1792 total_count:21878634 request_4xx:552 total_request_time:469576 | grep -Po '(?<=request_4xx:)\d+'
    552
    VShawn
        4
    VShawn  
       Sep 18, 2017
    (request_4\w\w:)\s?\d*\s
    替换为
    $1 553

    equest_5xx: 1792 total_count: 21878634 request_4xx: 552 total_request_time: 469576
    变为
    request_5xx: 1792 total_count: 21878634 request_4xx: 553 total_request_time: 469576
    krisbai
        5
    krisbai  
    OP
       Sep 18, 2017
    @yiyiwa 谢谢!
    krisbai
        6
    krisbai  
    OP
       Sep 18, 2017
    @VShawn。。额,已解决
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1027 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 19:33 · PVG 03:33 · LAX 12:33 · JFK 15:33
    ♥ Do have faith in what you're doing.