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

相关内容

热门资讯

超4800家上涨,沪指重返39... 3月25日,市场震荡反弹,沪指涨超1%重回3900点上方,创业板指涨超2%。截至收盘,沪指涨1.3%...
20多年来首次,中国车企超越日... 文/陈昊星如今,全球汽车市场发生重要变化,日本车卖不过中国车了。据《日本经济新闻》网站报道,日本汽车...
商务部:墨西哥相关涉华限制措施... 新京报讯 据商务部消息,根据《中华人民共和国对外贸易法》和《对外贸易壁垒调查规则》有关规定,商务部于...
中关村论坛开幕,2025年度“... 红星资本局3月25日消息,今日,2025年度“中国科学十大进展”在中关村论坛开幕式上发布。此次入选进...
刘强东现身哈尔滨革新市场,引发... 据“鞭牛士”消息,近日,京东集团董事局主席刘强东现身哈尔滨革新市场,一身正装亮相,气场十足,身旁有多...