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

如何用Grep命令从Kafka实例描述结果提取bootstrap_server_host值

Extract bootstrap_server_host value from Kafka describe output

Here are a few ways to get just the value of bootstrap_server_host from the JSON output:

Using grep with PCRE (Perl-compatible regex)

If your grep supports the -P flag (common in GNU grep), use this one-liner to directly extract the value:

rhoas kafka describe | grep -oP '(?<="bootstrap_server_host": ")[^"]+'
  • -o: Outputs only the matched part of the line, not the entire line.
  • -P: Enables PCRE, allowing lookbehind assertions to target text right after the key's quoted string.
  • The regex captures all characters after the key until the next double quote.

Using grep + sed (for systems without PCRE support)

If -P isn't available, combine grep with sed to strip extra content from the line:

rhoas kafka describe | grep bootstrap_server_host | sed 's/.*"bootstrap_server_host": "\([^"]*\)".*/\1/'
  • Grep isolates the line containing the target key.
  • Sed uses a regex to capture the value inside quotes and replaces the entire line with that captured group.

Better alternative: Use jq (JSON parser)

For reliable JSON handling (works with varying whitespace, nested structures, etc.), use jq instead of grep/sed. This is the most robust approach for JSON data:

rhoas kafka describe | jq -r '.bootstrap_server_host'
  • -r: Outputs the raw string without surrounding quotes.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 18:35:40