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

相关内容

热门资讯

经验总结“ 芒果竞技 怎么开... 您好:芒果竞技这款游戏可以开挂,确实是有挂的,需要了解加客服微信【6676724】很多玩家在这款游戏...
重磅.来袭“大众互娱 是不是... 您好:大众互娱这款游戏可以开挂,确实是有挂的,需要了解加客服微信【3398215】很多玩家在这款游戏...
今日资讯.么么棋牌辅助软件.辅... 您好:么么棋牌这款游戏可以开挂,确实是有挂的,需要了解加客服微信【8262836】很多玩家在这款游戏...
玩家推荐" 青鸟大厅... 亲.青鸟大厅这款游戏是可以开挂的,确实是有挂的,通过添加客服【9503776】很多玩家在这款游戏中怀...
重大发现.钱塘十三水开挂神器.... 亲.钱塘十三水这款游戏是可以开挂的,确实是有挂的,通过添加客服【9307068】很多玩家在这款游戏中...