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

相关内容

热门资讯

助贷平台大瓜!宜信将“良性清退... 5月24日消息,从早晨开始,社区平台陆续传出某财富机构即将bl,准备“良性清退”。当时,不少业内人士...
美以伊战争启示录|餐桌危机:不... 【编者按】1906年,美国记者兼小说家阿尔弗雷德·亨利·刘易斯说:“人类距离无政府状态只有九餐之隔。...
相爱相杀十年,《贪玩蓝月》和《... 2026 年 5 月,韩国游戏公司娱美德和中国游戏公司恺英网络,就传奇 IP 达成了全面和解,后者支...
张雪机车发布律师函 张雪机车发... 2026.05.24近期,市场上出现一本名为《勇敢追梦人:张雪的极致热爱与逆袭人生》(ISBN:97...
时隔两月再掀涨价潮!水泥行业盈... 财联社5月24日讯(记者 汪斌)在上半年传统施工旺季中,经历了今年3月“来去匆匆”的涨价失败后,财联...