<p>The file is this:</p>
<pre><code>- name: development
  cluster:
    certificate-authority: /etc/kubernetes/pki/ca.crt
    server: https://controlplane:6443

- name: kubernetes-on-aws
  cluster:
    certificate-authority: /etc/kubernetes/pki/ca.crt
    server: https://controlplane:6443

- name: test-cluster-1
  cluster:
    certificate-authority: /etc/kubernetes/pki/ca.crt
    server: https://controlplane:6443

contexts:
- name: test-user@development
  context:
    cluster: development
    user: test-user

- name: aws-user@kubernetes-on-aws
  context:
    cluster: kubernetes-on-aws
    user: aws-user

- name: test-user@production
  context:
    cluster: production
    user: test-user

- name: research
  context:
    cluster: test-cluster-1
    user: dev-user

users:
- name: test-user
  user:
    client-certificate: /etc/kubernetes/pki/users/test-user/test-user.crt
    client-key: /etc/kubernetes/pki/users/test-user/test-user.key
- name: dev-user
  user:
    client-certificate: /etc/kubernetes/pki/users/dev-user/developer-user.crt
    client-key: /etc/kubernetes/pki/users/dev-user/dev-user.key
- name: aws-user
  user:
    client-certificate: /etc/kubernetes/pki/users/aws-user/aws-user.crt
    client-key: /etc/kubernetes/pki/users/aws-user/aws-user.key

current-context: test-user@development
preferences: {}
</code></pre>
<p>i dont want to count how many diff clusters there is. HOw to count it with shell cmd?</p>
<pre><code>cat config.txt &gt; grep 'cluster' wc -l
</code></pre>
<p>is not working</p>

ERJAN
<p>You can use <code>kubectl config view</code> command with the help of <code>-o jsonpath</code> to list cluster names:</p>
<pre class="lang-sh prettyprint-override"><code>$  kubectl config view -o jsonpath='{.clusters[*].name}'
cluster-1 cluster-2 cluster-3
</code></pre>
<p>To count them:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl config view -o jsonpath='{.clusters[*].name}' | wc -w
3
</code></pre>
<p>You can also prettify your output by using <code>tr &quot; &quot; &quot;\n&quot;</code> command which will replace white space with a newline.</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl config view -o jsonpath='{.clusters[*].name}' | tr &quot; &quot; &quot;\n&quot;
cluster-1
cluster-2
cluster-3
</code></pre>
