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

相关内容

热门资讯

非息净收入腰斩,成都银行依然瑕... 出品|达摩财经黄建军回归后,成都银行(601838.SH)首次开启了中期分红。8月27日,成都银行发...
半年报|招行不良贷款率0.94... 招商银行今年上半年实现营业收入、净利润双增长。8月28日,招商银行(600036.SH/03968....
上涨农村养老金,到底对我们有多... 中国经济的下一轮活力,可能不在一线城市的金融产业,不在风口上的硬科技赛道,而在亿万农村老人的养老金账...
美团上半年仍亏46.7亿,外卖... 【财报】8月28日盘后,美团(3690.HK)交出二季度成绩单:收入1046亿元,同比增14.4%;...
科创板指数进行2026年三季度... 根据指数编制规则,科创50等科创指数样本每季度进行定期调整,本次调整将于9月11日收市后实施。其中,...