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

相关内容

热门资讯

新年资金入市!超450亿公募资... 新年行情暖意融融,公募增量资金持续入市。根据券商中国记者统计,截至1月10日2026年入市的公募资金...
姚顺雨“露脸”,和唐杰杨植麟探... “我相信今年可能是AI for Science的一个爆发年,因为很多能力大大提升,我们可以做更多的事...
碳积分可直接“换钱”!数字人民... 2026年伊始,数字人民币APP迎来一系列重磅更新。在完成2.0版本的升级、实现钱包余额计息功能后,...
闪迪:涨价,且必须全款! 存储芯片市场正经历一场由AI浪潮引发的供给侧剧变,卖方市场的强势回归令买家不得不接受前所未有的苛刻条...
宜家中国一次性关闭7家门店,2... 宜家(IKEA)将于2026年2月2日一次性关闭中国市场的7家门店,这在宜家进入中国 20 多年的历...