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

相关内容

热门资讯

朱宏任:宋志平新书《反内卷》是... 作者:朱宏任来源:认识管理(ID:gh_503913264134)2026年3月,备受瞩目的全国两会...
五粮液最“稳”董事长被查,什么... 五粮液(SZ.000858)董事长,又被查了据四川省纪委监委官网2月28日消息,四川省宜宾五粮液集团...
龙头股6个涨停!“特高压”,又... 特高压概念,又爆了!3月4日、5日,通达信特高压板块指数分别上涨2.36%、3.08%。龙头汉缆股份...
开年21家车企换人!一场关于权... 文 /杨雪健来源 / 节点财经2026年开年的汽车行业,比促销战更让人眼花缭乱的,是人。据不完全统计...
瑞幸还有定价权吗? 瑞幸还有定... 来源 | 伯虎财经(bohuFN)作者 | 路费新财报发布后,瑞幸陷入了一片质疑声中。一方面,瑞幸还...