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

相关内容

热门资讯

初代网红奶茶“一点点”被曝食安... 6月24日,针对《中国食品安全报》近日报道的关于部分门店存在食材效期管理混乱、员工操作卫生不规范及环...
马化腾 “漏船论” 之下,小微... AI进入场景生态比拼/AI图手工劳动/挖哥手工编辑 /角叔出品/独角兽观察6月底,拥有超14亿月活的...
中国投资人播客“从夯到拉”(2... 几个月前,我们曾经发布过一篇《中国投资人播客“从夯到拉”》,聊了聊VC做播客的必要性以及天然优势,并...
家电龙头,派发分红259亿元 ... 6月23日,美的集团正式发布2025年度A股利润分配实施公告,以剔除已回购股份后的68.2亿股为基数...
太子集团陈志"幕后大... *此图由AI生成作者| 史大郎&猫哥来源| 是史大郎&大猫财经Pro电诈大佬陈志都要喊一声“大哥”的...