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

相关内容

热门资讯

年入10亿,毛利不输海底捞,又... 订阅 快刀财经 ▲ 做您的私人商学院在经济下行期,餐酒吧生意还好做么?作者 :阿欣来源: 铅笔道(I...
贾国龙怒斥罗永浩恶意煽动公共情... 罗永浩与贾国龙的微博账号已均被禁言。1月16日晚间,在行业的高度关注中,西贝创始人贾国龙并未如外界预...
振芯科技信披违规收警示函,此前... 微成都报道1月14日,振芯科技(300101.SZ)及公司相关负责人因涉违规披露董事会换届信息,收到...
TCL中环拟投资“光伏黑马” ... 中经记者 张英英 吴可仲 北京报道1月16日晚间,TCL中环(002129.SZ)发布公告称,公司正...
靠极致“抠门”,萨莉亚在中国“... 出品|虎嗅商业消费组作者|李佳琪编辑|苗正卿题图|萨莉亚1月初某工作日中午12点30分左右,虎嗅走进...