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年中海地产净利润130.1亿元,是全行业仅有的两家利润超百亿的房企。文/每日财报 南黎20...
约40名博士领衔AI药物递送,... 本文来源:时代商业研究院 作者:时代商业研究院来源丨时代商业研究院作者丨实习生杨军微编辑丨郑琳202...
百万包装“伪进口”,网红爆品“... 21世纪经济报道记者 刘婧汐4月1日,央视总台报道“进口”保健品乱象,抖音、天猫销量第一的叶黄素知名...
六大行2025年业绩答卷:全员... 全文共4709字,阅读全文约需10分钟过去一年,六大行总资产规模合计突破220万亿元大关,增速显著跑...