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

相关内容

热门资讯

新海贝房卡充值“新道游正版房卡... 新海贝房卡充值“新道游正版房卡多少钱”美猴王房卡购买联系方式;通过微信添加客服:1582660429...
新天道大厅怎么买房卡“新众亿大... 新天道大厅怎么买房卡“新众亿大厅房卡在哪里买”牛牛房卡的购买价格是多少;通过微信添加客服:15826...
天道联盟在哪能充到房卡“人皇牛... 天道联盟在哪能充到房卡“人皇牛牛房卡在哪里可以购买”微信金花购买房卡;通过微信添加客服:158266...
新道游房卡代理平台“新天道大厅... 新道游房卡代理平台“新天道大厅怎么买房卡”皇豪互娱房卡怎么买科技;通过微信添加客服:15826604...
牛牛房卡在哪里购买“九酷众娱房... 牛牛房卡在哪里购买“九酷众娱房卡批发”火神大厅房卡怎么卖;通过微信添加客服:1582660429牛牛...