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

Linux sed 的命令

  •  
  •   1054850490 · 2022-06-09 08:41:06 +08:00 · 2616 次点击
    这是一个创建于 658 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如图所示

    假如我的输入为“id”
    jq -r ".id" | sed "s_^_/watch?v=_"
    那么这行代码会输出结果为:/watch?v=id


    那么如何让他输出两个结果?假如我的输入还是 id ,但是一次性打印并替换为两份
    如图下
    5 条回复    2022-06-09 22:15:29 +08:00
    somicimos
        1
    somicimos  
       2022-06-09 08:58:25 +08:00   ❤️ 1
    sed -e "s_^_/watch?v=_p" -e "s_^/watch?v=_/shorts/_"
    1054850490
        2
    1054850490  
    OP
       2022-06-09 09:02:47 +08:00
    @somicimos 谢谢哥,问题完美解决了
    1and0
        3
    1and0  
       2022-06-09 14:59:12 +08:00 via iPhone
    @somicimos 新手问下下划线是啥意思,网上没搜出来
    somicimos
        4
    somicimos  
       2022-06-09 17:55:57 +08:00
    @1and0 分隔符而已,也可以是#等,例如"s#^/watch?v=#/shorts/#"
    1and0
        5
    1and0  
       2022-06-09 22:15:29 +08:00
    @somicimos 谢谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5471 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 08:28 · PVG 16:28 · LAX 01:28 · JFK 04:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.