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

相关内容

热门资讯

「站起来」赚钱的宇树,市值能冲... 「核心提示」机器人IPO浪潮已至,宇树率先冲线,智元、傅利叶们接踵而来,谁能真正“站”稳?作者 | ...
网友戏称:“黄金猴市”来了 黄... 3月23日,国际黄金市场迎来大幅下挫,现货黄金一度跌破4100美元/盎司关键位,年内所有涨幅尽数被抹...
两个突发消息,风向又变了! 两... 昨晚的消息真真假假,无法分辨。但一个基本的概况就是——美国方面坚决声称他们和伊朗正在协商,准备谈判。...
建行信用卡中心、尚诚消费金融涉... 全文共733字,阅读全文约需2分钟3月23日,国家金融监督管理总局上海监管局公布多则行政处罚信息公开...
万亿风口上的中医“龙头”,战乱... 乘AI东风,一家百年老字号,正开辟“新航线”。同仁堂医养,战乱世界的“压舱石”,已经站上了价值迁跃的...