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

相关内容

热门资讯

恺英网络“神秘老友”现身,12... 出品|达摩财经5月15日,金海高科(603311.SH)发布公告称,公司控股股东汇投控股及其一致行动...
A股新“股王”,提示风险 a股... 5月18日,联讯仪器(688808)股价收盘上涨15%,成为A股新“股王”。当日晚,联讯仪器公告提示...
洛轴股份:高杠杆下的上市豪赌,... 图片系AI生成从2004年的走投无路、一度寻求卖身德国巨头算起,洛阳轴承集团股份有限公司(洛轴股份)...
应流股份的“估值虚火”:20亿... 本文来源:时代商业研究院 作者:郝文然 韩迅 图源:图虫创意来源|时代商业研究院作者|郝文然 韩迅编...
AI将首次全场景、全产业融入“... 今日,京东在京召开媒体发布会,宣布2026年京东618将于5月30日晚8点正式开启。而今年京东618...