V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
826540272
V2EX  ›  Linux

请教一下 sed/ awk 的用法

  •  
  •   826540272 · Aug 2, 2021 · 2140 views
    This topic created in 1735 days ago, the information mentioned may be changed or developed.
    用来把 ipv6 地址转换成固定的 ipv6 前缀
    大概就是删除第四个冒号及其之后的所有内容 /保留第四个冒号之前的所有内容
    2001:db80::a00:27ff:fe67:cd9c

    查了挺久没查到,用来给路由器内网设备分配 ipv6 ddns 的
    7 replies    2021-08-05 17:09:26 +08:00
    FurN1
        1
    FurN1  
       Aug 2, 2021
    你要学的是 regex,然后在 sed/awk 里用
    Atomo
        2
    Atomo  
       Aug 3, 2021 via Android
    Atomo
        3
    Atomo  
       Aug 4, 2021 via Android
    kaiger
        4
    kaiger  
       Aug 4, 2021
    echo “2001:db80::a00:27ff:fe67:cd9c” | awk -F ':' '{print $1":"$2"::"$4}'

    输出:2001:db80::a00
    s5unty
        5
    s5unty  
       Aug 5, 2021
    ```
    % echo "2001:db80::a00:27ff:fe67:cd9c" | cut -d':' -f-4
    2001:db80::a00
    % echo "2001:db80::a00:27ff:fe67:cd9c" | cut -d':' -f4-
    a00:27ff:fe67:cd9c
    ```
    826540272
        6
    826540272  
    OP
       Aug 5, 2021
    已经解决了,用 cut -d: -f1-4
    很简单
    826540272
        7
    826540272  
    OP
       Aug 5, 2021
    @s5unty 对,我用的就是这个
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2421 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 04:43 · PVG 12:43 · LAX 21:43 · JFK 00:43
    ♥ Do have faith in what you're doing.