I'm working with Apache Geode nodes, all of the work is being done via the Linux CLI. Normally when I edit the config files (with VIM) the text looks like this:

"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}

...and that's just one node. There are often several of them, and the text is just all globbed together in a big hard-to-read mess. What would make this a ton easier is if I could view and edit the file like so:

"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

I know this is possible and I've seen it before, but I don't know how it's done.

Update: I have to point out, this is a SLES Appliance (often with no internet access) so I cannot install any app, such as jq

  • Is that supposed to be valid JSON? If so, you could use jq or similar to format it: vi.stackexchange.com/a/19950/205 – muru Apr 16 at 3:06
  • Thank you, @muru. These are not actually JSON files, but you're right to say the layout is of course similar...so I'm actually not sure. These are like .dat files. The issue is that I'm working from a Linux appliance (closed source), so I cannot install a package and it does not have the jq utility. – SamAndrew81 Apr 16 at 3:10
  • What do you have available? Python? Whilst you may not be able to install a package can you install a binary in say ~/bin ? – icarus Apr 16 at 4:00
  • Thanks, yes, the appliances either have Python 2 (older ones) or Python 3. – SamAndrew81 Apr 16 at 4:03

A colleague of mine from DevOps showed me how to do this with sed + regEx + json.tool:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.