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

相关内容

热门资讯

半年报现多处低级文字错误,紫金... 近日,大型跨国矿业集团紫金矿业(601899.SH/02899.HK)2026 年半年度报告因多处基...
摩尔线程回应20%跌停 摩尔线... 9月7日,国产GPU厂商摩尔线程(688795.SH)盘中20%跌停,市值跌破2000亿元。根据公告...
IPO前的军备竞赛!Anthr... Anthropic过去11个月密集签署算力协议,总价值高达5170亿美元。这场采购狂潮的直接导火索,...
旺峰肉业因投标提供虚假材料遭军... 8 月 27 日,军队采购网发布公告,新三板肉类企业重庆旺峰肉业股份有限公司(871308)因投标提...
记者暗访化妆品“地下工厂”:冒... 新京报我们视频调查记者民房制假,专人放风,监控遍布——广东汕头和平镇的化妆品造假工厂比想象的更“专业...