linux awk获取倒数某一列
创始人
2025-05-28 02:10:45

结果可以从man手册找到

  • -F参数
    -F fs
    –field-separator fs
    Use fs for the input field separator (the value of the FS predefined variable).

    -F参数指定用于分割的字符或者是字符串。

  • Fields
    As each input record is read, gawk splits the record into fields, using the value of the FS variable as the field separator.If FS is a single character, fields are separated by that character. If FS is the null string, then each individual character becomes a separate field.

  • NF(代表的是被分割后的字段总数)
    The variable NF is set to the total number of fields in the input record.

以下字段为例:
| `- 17:0:0:0 sdl 8:176 active ready running

  • 获取以空格为分隔符,倒数第一列数据
echo '| `- 17:0:0:0  sdl  8:176  active ready running' | awk -F " " '{print $NF}'

结果为:running

  • 获取以空格为分隔符,倒数第二列数据
echo '| `- 17:0:0:0  sdl  8:176  active ready running' | awk -F " " '{print $(NF-1)}'

结果为:ready

相关内容

热门资讯

军方采购“零容忍”:永辉彩食鲜... 近日,军队采购网发布一则处罚公告,永辉彩食鲜供应链管理有限公司因在采购活动中提供虚假材料,被陆军采购...
贝壳年二手单量历史新高,5亿投... 3月16日,贝壳(NYSE:BEKE;HKEX:2423)发布2025年全年&Q4业绩数据。2025...
利润翻倍!周生生甩出王炸财报预... 3月17日,港股老牌珠宝商周生生股价迎来大幅异动,受前一晚超预期盈利预告提振,股价早盘高开近9%,盘...
20%员工或被裁、1.6万人离... 文 /杨雪健来源 / 节点财经Meta或迎来史上最大规模裁员潮。2026年3月14日,路透社曝出Me...
美宜佳真有自己卷烟厂?中国便利... 出品丨花朵财经观察(FF-Finance)撰文丨华见2026年3·15,坐拥4万多家门店的“中国便利...