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

相关内容

热门资讯

4个月能长3厘米?起底“长高神... 澎湃新闻记者 史含伟 编辑 顾亚敏不少电商平台销售的“ GroupCare格瑞卡小鹿冲冲赖氨酸生长素...
Clawdbot风波的隐喻:“... 本文系基于公开资料撰写,仅作为信息交流之用,不构成任何投资建议。一场由商标争议引发的强制更名,在短短...
教培机构拖欠百万元预付款想跑路... 来源:济南时报近日,济南铁路运输两级法院依法审结山东省首例职业闭店行政撤销案件,针对山东某儿童教培机...
不拔管,百万赔偿就没了 “深昏迷,双侧瞳孔等大等圆,直径约5毫米,对光反射消失。”这是2024年11月1日上午9时,广东东莞...
金价大涨!台州有人给孩子买三金... 来源:台州晚报近段时间,贵金属延续了过去一年的迅猛涨势,屡创新高。1月28日,国际金价突破了5300...