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

相关内容

热门资讯

小赢科技2025年全年业绩发布... 北京时间3月26日,美股上市金融科技集团小赢科技发布了其截至2025年12月31日的第四季度及年度未...
《流金谷》的故事从来不新鲜,可... 《流金谷》刷屏了,央视的ai制作当然很精美,但这片子哪里是什么隐喻,它就是明指哈梅内伊被斩首后,大美...
融创服务:去年归母净利润约2.... 3月25日,融创服务(01516.HK)披露2025年全年业绩。财务数据显示,2025年收入约为68...
中国移动:去年实现归母净利润1... 新京报贝壳财经讯 3月26日,中国移动港交所公告,2025年营运收入为人民币10502亿元,同比增长...
1.4万亿外储压阵!日本拟下场... 为了阻止日元跌向160大关,日本财务省被曝考虑“突袭油市”,动用1.4万亿美元外储建立“国家级空头”...