You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用jq及awk/sed生成线程兄弟节点的可读有序列表?

用JQ实现线程兄弟节点的易读格式化

场景1:按每个CPU的线程兄弟节点分别输出

  • 逗号分隔格式:
    os baremetal introspection data save compute0 | jq -r '.numa_topology.cpus[] | select(.numa_node == 0) | .thread_siblings | sort | join(", ")'
    
  • 空格分隔格式:
    os baremetal introspection data save compute0 | jq -r '.numa_topology.cpus[] | select(.numa_node == 0) | .thread_siblings | sort | join(" ")'
    

场景2:合并所有NUMA节点0的线程兄弟节点(去重+全局排序)

  • 逗号分隔格式:
    os baremetal introspection data save compute0 | jq -r '[.numa_topology.cpus[] | select(.numa_node == 0) | .thread_siblings[]] | unique | sort | join(", ")'
    
  • 空格分隔格式:
    os baremetal introspection data save compute0 | jq -r '[.numa_topology.cpus[] | select(.numa_node == 0) | .thread_siblings[]] | unique | sort | join(" ")'
    
结合AWK/SED的处理方案

如果需要用传统文本工具辅助,可先通过JQ提取原始数字,再做格式化:

逗号分隔格式

os baremetal introspection data save compute0 | jq '.numa_topology.cpus[] | select(.numa_node == 0) | .thread_siblings[]' | sort -n | uniq | awk '{printf "%s%s", sep, $0; sep=", "} END{print ""}'

空格分隔格式

os baremetal introspection data save compute0 | jq '.numa_topology.cpus[] | select(.numa_node == 0) | .thread_siblings[]' | sort -n | uniq | xargs

内容的提问来源于stack exchange,提问作者amkgi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 19:09:51