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

相关内容

热门资讯

袁记云饺冲刺港股,前肯德基中国... 1月12日,袁记食品集团股份有限公司(下文简称“袁记云饺”)在香港联交所递交上市申请,其联席保荐人为...
众安系科技平台资本化加速,“A... 出品|达摩财经日前,众安信科(深圳)股份有限公司(下称“众安信科”)递表港交所,联席保荐人为工银国际...
A股放量走高,热点轮动逐步加快... 15个月之后,A股成交额终于创出历史新高。1月12日,上证指数延续跨年行情的上涨惯性高开高走,全天上...
一场跨越千里的应援,把洋河推到... 2026年“苏超”尚未正式开赛,战火已经在千里之外的湖南永州燃起。2025年12月27日,在首届“湘...
关店背后,宜家在中国不「香」了... 「核心提示」关大店、开小店:宜家在中国能靠“瘦身”翻身吗?作者 | 詹方歌编辑 | 邢昀1月上旬,一...