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

相关内容

热门资讯

三六零首任董秘公开追讨2600... 本文来源:时代周报三六零(601360.SH)首任董秘突然发难讨薪。7月24日下午,曾经担任360首...
银轮股份:不锈钢板式换热器等产... 新京报贝壳财经讯 7月25日,银轮股份在互动平台表示,公司目前在数据中心领域,明确了数据中心液冷模组...
周预测:有底 周预测:有底 周... 我们说过,目前的市场是“皮市”。沪指7月13日跌破250日线,就是技术性熊市,不过沪指跌到3741点...
2026中国汽车论坛:大咖共论... 红星资本局7月25日消息 7月21日至7月23日,2026中国汽车论坛在上海嘉定举办。今年论坛设置1...
绿城中国换帅,大股东中交集团话... 此次调整打破了绿城中国长期实行的董事会主席与行政总裁分设的惯例,意味着公司决策权和经营权进一步集中文...