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

相关内容

热门资讯

浙江嘉善农商行领 230 万元... 国家金融监督管理总局嘉兴监管分局对外公布行政处罚,浙江嘉善农村商业银行股份有限公司因违规发放项目贷款...
官方发文,一把手带头休假,最不... 这两天,大河南的一份红头文件刷屏了。8月5日,河南省委组织部、人社厅、商务厅等六部门联合印发通知,要...
富滇银行重庆分行授信风控全面失... 近日,国家金融监督管理总局重庆监管局公布行政处罚决定书,富滇银行股份有限公司重庆分行因授信风险管理失...
宇树科技610亿估值落地,又一... 2026年8月6日晚间,宇树科技一纸发行公告搅动整个科创板。150.80元/股的定价尘埃落定,发行后...
量贩零食的“冰与火之歌” 量贩... 来源 | 伯虎财经(bohuFN)作者 | 林恩在加速扩张后,量贩零食迎来了相对“克制”的发展阶段。...