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

相关内容

热门资讯

世纪互联涨超24%,宣布引入新... 世纪互联宣布引入与宁德时代关联的战略投资者,交易完成后新股东将持有公司约38.1%的股份据世纪互联5...
美国车里,也就特斯拉还能在特朗... 出品|虎嗅汽车组作者|杨杰题图|视觉中国2026年5月13日,特朗普访华,成了这个春天最热闹的外交新...
光伏巨头集体出售美国公司股权 ... 5月8日,晶科能源一则出售美国工厂控股权的公告,在光伏行业掀起轩然大波。公司全资子公司晶科美国控股拟...
要考虑加息了?美国通胀指标连续... 受霍尔木兹海峡能源冲击持续向通胀链条传导影响,美国上月生产者物价涨幅创下2022年以来新高,令市场对...
华尔街疯抢,报道称AI芯片Ce... AI芯片制造商Cerebras Systems正以远超预期的热度冲刺美股市场,其IPO定价区间一再被...