如何以可讀的格式列出 Linux CLI 中括號內的文字? Apache Geode 節點名稱和訊息

如何以可讀的格式列出 Linux CLI 中括號內的文字? Apache Geode 節點名稱和訊息

我正在與Apache Geode 節點,所有工作都是透過 Linux CLI 完成的。通常,當我編輯設定檔(使用 VIM)時,文字如下所示:

"nodes": {"long_UUID_here": {"node_uuid": "another_long_string_here", pair_uuid:" null, 
"is_admin_node": false, "ip_address": "ip-or-fqnd.domain.com", "preferred_addresses": {}, 
"node_name": shortname.domain.com", "membership_state": null, "region": null}

……這只是節點。通常有好幾個,而且文字都亂七八糟地拼湊在一起,難以閱讀。如果我可以像這樣查看和編輯文件,將使這變得更加容易:

"nodes": {  
    "long_UUID_here": {  
        "node_uuid": "another_long_string_here",  
        "pair_uuid:" null,  
        "is_admin_node": false,
        "ip_address": "ip-or-fqnd.domain.com", 
        "preferred_addresses": {}, 
        "node_name": shortname.domain.com",
        "membership_state": null,
        "region": null
}

我知道這是可能的,而且我以前見過它,但我不知道它是如何做到的。

更新:我必須指出,這是一個 SLES 裝置(通常無法存取互聯網),因此我無法安裝任何應用程式, 例如jq

答案1

我的一位 DevOps 同事向我展示瞭如何使用sed+ regEx +來做到這一點json.tool

`echo sed -nre "/clusterMembership/ s/^[^']+'([^']+)','([^']+)'.*/\2/p" /path/to/file/here/node.file.config | python -m json.tool

相關內容