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

相关内容

热门资讯

从2000元到300元,降脂药... 出品 | 妙投APP作者 | 张贝贝编辑 | 丁萍头图 | 视觉中国近期,“降脂针进医保后仅300元...
服务县域基层医疗!好医生云医疗... 本文来源:时代商业研究院 作者:时代商业研究院 图源:图虫创意来源丨时代商业研究院作者丨实习生杨军微...
华大尹烨带货的益生菌,没有“蓝... “经常在床上像烙饼一样翻来覆去,早上起来特别不得劲的家人们,都可以看看咱们这一款产品。”在华大优美达...
内存危机深化:DRAM厂商预计... AI算力需求的爆发式增长正将全球DRAM市场推向一场旷日持久的供给危机。最新行业数据显示,即便三星、...
天孚通信冲刺“A+H”!瞄准A... 本文来源:时代商业研究院 作者:时代商业研究院 图源:图虫创意来源|时代商业研究院作者|实习生陈嘉婕...