如何用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
相关产品推荐
相关产品推荐

