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

相关内容

热门资讯

券商资管分化加剧!前十狂揽近九... 年报一出,证券行业各业务条线的最新概貌也跃然纸上。2025年,在政策优化与市场回暖的双重利好下,资产...
国货美妆龙头珀莱雅失速:上市以... 营收破百亿后的一年,国货美妆龙头褪去高光。4月21日,珀莱雅(603605.SH)发布2025年年报...
威邦运动再闯IPO:换报告期“... 文 | 张佳儒4月15日,威邦运动科技集团股份公司(以下称“威邦运动”)招股书在证监会官网更新披露,...
1.3万亿超长期国债来了:这笔... 4月24日,财政部正式发行今年首期超长期特别国债。消息发布那天,财经媒体的标题里出现了一个数字:1....
高喊爱国就关厂?别急,曹德旺的... 最近,曹德旺在股东会上的一句话又刷屏了。面对特朗普对中国挥舞关税大棒,这位实业大佬直言:“我是个体户...