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

请教一下 sed/ awk 的用法

  •  
  •   826540272 · Aug 2, 2021 · 2670 views
    This topic created in 1920 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
    FurN1
    Aug 2, 2021
    1
    你要学的是 regex,然后在 sed/awk 里用
    Atomo
    Atomo
    Aug 3, 2021 via Android
    2
    kaiger
    kaiger
    Aug 4, 2021
    4
    echo “2001:db80::a00:27ff:fe67:cd9c” | awk -F ':' '{print $1":"$2"::"$4}'

    输出:2001:db80::a00
    s5unty
    s5unty
    Aug 5, 2021
    5
    ```
    % 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
    826540272
    OP
    Aug 5, 2021
    6
    已经解决了,用 cut -d: -f1-4
    很简单
    826540272
    826540272
    OP
    Aug 5, 2021
    7
    @s5unty 对,我用的就是这个
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3015 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 12:16 · PVG 20:16 · LAX 04:16 · JFK 07:16
    ♥ Do have faith in what you're doing.