<p>I'm using kubernetes, and I want to get podname from the app name. Here is the command I use.</p>

<pre><code>POD=$(kubectl get pods -l app=influxdb-local -o custom-columns=:metadata.name -n influx)
</code></pre>

<p>Then I would like to use the result in:</p>

<pre><code>kubectl exec -it -n influx $POD -- influx -username user -password "user" -execute "CREATE DATABASE db"
</code></pre>

<p>but the first line is empty, and the second line contains pod name, so the second command doesn't work.</p>

<p>How should I remove the first white line ?</p>

Juliatzin
<p>Add <code>--no-headers</code> to skip the header line</p>

<pre><code>kubectl get pods -l app=influxdb-local -o custom-columns=:metadata.name -n influx --no-headers
</code></pre>

<h1>Custom Columns</h1>

<p>Using the flag <code>-o custom-columns=&lt;header-name&gt;:&lt;field&gt;</code> will let you customize the output.</p>

<p>Example with resource name, under header <code>NAME</code></p>

<pre><code>kubectl get pods -o custom-columns=NAME:metadata.name
</code></pre>

<p>output</p>

<pre><code>NAME
myapp-5b77df6c48-dbvnh
myapp-64d5985fdb-mcgcn
httpd-9497b648f-9vtbl
</code></pre>

<p><strong>Empty header name:</strong> you used the flag as <code>-o custom-columns=:metadata.name</code> - the first line is the header line, but with an empty header.</p>

<h2>Omit headers</h2>

<p>the proper solution to omit the header line is by using the flag <code>--no-headers</code></p>

<pre><code>kubectl get pods -o custom-columns=NAME:metadata.name --no-headers
</code></pre>

<p>Example output</p>

<pre><code>myapp-5b77df6c48-dbvnh
myapp-64d5985fdb-mcgcn
httpd-9497b648f-9vtbl
</code></pre>
