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

相关内容

热门资讯

年销30亿瓶!曾被无数人误认“... 在网络尚不发达,信息传播滞后的年代,有不少外国货,因为中国化的名字而被误认为是国货,有些甚至直到今天...
500ML飞天上线i茅台,消费... 2026年1月1日起,到“i茅台”购买500ml飞天茅台,成为酒圈最关心的话题。在线上热卖的同时,有...
创历史新高!2025年中国航天... 据央视新闻消息,记者从国家航天局获悉,2025年,我国在载人航天、深空探测、商业航天等领域完成多项突...
山姆与小象超市共享同一供应商?... 近日,有网友发帖称,小象超市与山姆会员商店的供应链已趋同,自己在两家实体店购买的多款产品来源一致,因...
多地门店跑路!洗脸熊致歉:对跑... 近日,由知名艺人古天乐代言的面部清洁护理连锁品牌“洗脸熊·洗脸吧”(下称“洗脸熊”)被曝多地门店跑路...