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

相关内容

热门资讯

“电动车换电大王”递表港交所!... 据港交所5月29日披露,智租物联科技集团股份有限公司向港交所主板递交上市申请,申万宏源香港为独家保荐...
“停摆”三年的天涯社区重启,用... 红星资本局6月1日消息,停止运营三年后,天涯社区官宣今日起启用新域名正式开放访问,网址变更为www....
消纳、碳壁垒、降本三重压力 绿... 当前,新能源装机规模持续高速增长,消纳矛盾日益突出。截至“十四五”末期,我国新能源总装机规模已达19...
天涯“复活”首日!总编喊话俞浩... 在上网都有很高门槛的1999年3月,天涯社区悄然成立,很快便以表达自由吸引了一众文化青年,他们在这个...
出资 10.01 亿元 中国国... 近日,国新钱江创业投资基金(杭州)合伙企业(有限合伙)完成注册设立,基金认缴出资总额 10.01 亿...