Home > OS >  How to concatenate output from -o=custom-columns?
How to concatenate output from -o=custom-columns?

Time:10-04

I'm trying to concatenating an output from oc get in openshift, I'm using -o=custom-columns but it's not joining 2 equal values ​​when I get the normal output...

{
    "roleRef":{
        "kind": "ClusterRole",
        "name": "view"
 }
}

The result I wanted is that in the same column the values ​​of "kind" and "name" come out like this:

ROLE
ClusterRole/view

If I give an "oc get rolebinding" in openshift it already gives me this return, but if I use -o=custom-columns to edit the columns as I prefer, I didn't find a way to convert this, can you help me?

CodePudding user response:

Unfortunately kubectl/oc only supports simplistic jsonpath expressions for -o custom-columns. If you really want to display this as a single column (as opposed to just displaying two separate columns), you'll have to rely on -o jsonpath. What this would look like:

$ oc get rolebinding -o jsonpath='{range .items[*]}{.roleRef.kind}{"/"}{.roleRef.name}{"\n"}{end}'

It's obviously a bit more verbose, but infinitely more customizable. Hope this helps!

For what it's worth, if you want/need to get more fancy with column headers, etc, it would look something like

$ oc get rolebinding -o jsonpath='{"NAME"}{"\t"}{"ROLE"}{"\n"}{range .items[*]}{.metadata.name}{"\t"}{.roleRef.kind}{"/"}{.roleRef.name}{"\n"}{end}'
  • Related