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

相关内容

热门资讯

实测了解“闲来玩游戏究竟有挂吗... 您好:闲来玩游戏这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9951342】很多玩家在这款游...
老玩家实测“西兵互娱炸金花怎么... 您好:西兵互娱炸金花这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这...
玩家攻略“邳州麻将.究竟有挂吗... 您好:邳州麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【8435338】很多玩家在这款游戏...
我来教教您“掌酷十三张.开挂神... 您好:掌酷十三张这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9158489】很多玩家在这款游...
科技揭秘“欢乐斗地主掼蛋真的有... 您好:欢乐斗地主掼蛋这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9752949】很多玩家在这...