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

相关内容

热门资讯

这款月销四万的“冷门车”,把新... 出品|虎嗅汽车组作者|邢书博头图|比亚迪这几天,所有车圈媒体都盯着雷军说要“用新车干特斯拉”,盯着F...
股价暴跌!富途控股被罚18.5... 跨境券商违规开展业务的罚单落地。5月22日,富途控股、老虎证券相继公布了监管机构的拟处罚金额,两家跨...
证监会拟对富途罚款18.5亿,... 澎湃新闻记者 孙铭蔚中国证监会5月22日宣布,近日依法对Tiger Brokers(NZ)Limit...
与19家客户打官司,踩雷合众汽... 本文来源:时代商业研究院 作者:陆烁宜图源:图虫创意来源丨时代商业研究院作者丨陆烁宜编辑丨郑琳与19...
恒润达生商业化困局:零营收、累... 本文来源:时代商业研究院 作者:研究员赖钧洪、郑琳图源:图虫创意来源|时代商业研究院作者|研究员赖钧...