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

相关内容

热门资讯

小鹏副总裁回应“L3L4自动驾... 红星资本局6月20日消息,6月19日晚间,小鹏集团(09868.HK/XPEV.US)副总裁于涛在社...
学习英伟达“好榜样”,谷歌和博... 英伟达用财务担保和循环融资构建的AI芯片商业帝国,正在被它最强劲的竞争对手们逐一复制。谷歌和博通正以...
SemiAnalysis:半数... 美国数据中心建设放缓的悲观叙事席卷市场,但空头情绪背后的数据真相,正让理性投资者重新审视这场集体误判...
以黎局势挑动市场神经,欧股一度... 原定周五举行的美伊谈判取消,直接决定谈判走向的以色列和黎巴嫩局势挑动市场神经。据央视新闻,伊朗外交部...
Momenta港股上市迈出关键... 作者 | 周智宇6月18日,中国证监会向Momenta Global Limited(梦腾智驾环球有...