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

相关内容

热门资讯

良品铺子卖菜了 良品铺子卖菜了... 零食连锁——良品铺子也转型社区超市卖菜了。日前,良品铺子做的“良品铺子鲜生活”首店于武汉汉口城市购物...
长鑫科技2025年实现盈利  ... 中经记者 陈佳岚 广州报道在DRAM(动态随机存取存储器)行业上行的超级周期中,长鑫科技集团股份有限...
酱香拿铁之后瑞幸又出新品,咖啡... 前几年,瑞幸推出酱香拿铁曾经引发过市场的热议,当时成为了最受欢迎的网红,不过之后含酒精的饮品就消失了...
漳州杨梅崩了1.2亿:违规的被... 2026年5月,有人拿着摄像机,走进了福建漳州浮宫杨梅的收购点。镜头里,商贩把一筐筐杨梅倒进盛满液体...
第160期:42.65 第16... 2026年5月15日更新:【#大V综合信号#】42.65可买可卖(上期37.95)