<p>I am trying to get a list of kube-contexts (and filtering for gke clusters) and <a href="https://unix.stackexchange.com/questions/109835/how-do-i-use-cut-to-separate-by-multiple-whitespace">with some tools</a> ended up with that:</p>
<pre><code>kubectl config get-contexts | tr -s ' ' | cut -d ' ' -f 2 | grep gke
</code></pre>
<p>output:</p>
<pre><code>gke_dev-redacted
gke_prod-redacted
</code></pre>
<p>Is there an easier way to do that (which does not depend on the fact that the command output does not use tabs, but multiple whitespaces). yaml or json output is not supported by that command:</p>
<pre><code>--output yaml is not available in kubectl config get-contexts; resetting to default output format
</code></pre>

user140547
<p>You can provide the <code>--output</code> flag to display only the contexts' names, for example:</p>
<pre><code>$ kubectl config get-contexts --output=name
minikube
</code></pre>
<p>It's then easy to grep for GKE contexts:</p>
<pre><code>$ kubectl config get-contexts --output=name | grep &quot;gke_*&quot;
</code></pre>
