V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
krisbai
V2EX  ›  Linux

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

  •  
  •   krisbai · 2017-09-18 16:53:54 +08:00 · 1481 次点击
    这是一个创建于 2403 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如题 。文本内的内容为:request_5xx:1792 total_count:21878634 request_4xx:552 total_request_time:469576
    假如想要 单独截取 request_4xx 对应的 552 改如何匹配呢?
    6 条回复    2017-09-18 17:08:52 +08:00
    VShawn
        1
    VShawn  
       2017-09-18 16:57:09 +08:00
    正则表达式不行吗?
    Immortal
        2
    Immortal  
       2017-09-18 17:00:52 +08:00
    正则表达式不行吗?
    yiyiwa
        3
    yiyiwa  
       2017-09-18 17:02:47 +08:00
    echo request_5xx:1792 total_count:21878634 request_4xx:552 total_request_time:469576 | grep -Po '(?<=request_4xx:)\d+'
    552
    VShawn
        4
    VShawn  
       2017-09-18 17:03:19 +08:00
    (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
       2017-09-18 17:07:51 +08:00
    @yiyiwa 谢谢!
    krisbai
        6
    krisbai  
    OP
       2017-09-18 17:08:52 +08:00
    @VShawn。。额,已解决
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5361 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:22 · PVG 15:22 · LAX 00:22 · JFK 03:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.