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

相关内容

热门资讯

精度季报丨陈皓:看好AI和化工... (本文仅仅是个人角度的臆想分析,不能作为投资建议。)牛市来了,人人都会炒股了...就比如基毛哥,之前...
A股首次,连续14年造假,操盘... 在A股市场的发展历程中,上市公司财务造假事件时有发生,但持续时间长达十四年、跨越收购前后、实际控制人...
锦江酒店副总裁赵雁飞辞任 新京报贝壳财经讯 1月24日,锦江酒店发布公告,因到龄退休,公司副总裁赵雁飞申请辞去公司副总裁职务。...
“马茅”市场价报2250元,溢... 红星资本局1月24日消息,贵州茅台(600519.SH)推出的生肖酒开启了第二个轮回。红星资本局注意...
“电子木鱼”火了!泡泡玛特股价... 中国商报(记者 冉隆楠 文/图)、、、……近日,泡泡玛特门店时不时传出敲木鱼的声音——这是该品牌旗下...