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

相关内容

热门资讯

一年近3500次汽车“碰撞测试... C-NCAP正面50%重叠移动变形壁障碰撞试验。 中国汽车技术研究中心供图文/陈昊星在中国汽车产业发...
八一钢铁可能被实施退市风险警示... 八一钢铁可能被实施退市风险警示(资料图)北京商报讯(记者 马换换 李佳雪)1月25日晚间,八一钢铁(...
华神科技业绩预亏 继2024年净利出现亏损后,2025年,华神科技(000790)归属净利润预计再次出现亏损。在业绩连...
存储狂潮!高盛1月渠道调查:D... 如果你正在寻找半导体周期的确切信号,高盛亚太团队刚刚发布的2026年1月DRAM市场情绪指标不仅闪烁...
5个月涨10倍!“U盘牛夫人”... 仅仅五个月前,闪迪还被视为一家由于技术过时而步履蹒跚的老牌存储卡公司,其主要产品USB闪存盘和数码相...