<p>I was trying to redirect logs of pods in a k8s into a file of their name.</p>

<p><code>kubectl get pods | awk '{print $1}' | tail -2 | xargs -I {} kubectl logs {} &gt; {}</code></p>

<p>This is the result.</p>

<p><code>demo@demo1:~/log$ ls
{}</code></p>

<p>What I need is, if this is the pod details</p>

<p><code>demo@demo1:~/log$ kubectl get pods
NAME                              READY   STATUS      RESTARTS   AGE
pod1                              1/1     Running     0          3d23h
pod2                              1/1     Running     0          3d23h
</code>
The expected result is</p>

<p><code>demo@demo1:~/log$ ls
pod1  pod2</code></p>

<p>files pod1 &amp; pod2 will have logs of respective pods.</p>

Yasir
<pre><code>kubectl get pods | awk '{print $1}' | tail -n +2 | xargs -I{} sh -c 'kubectl logs $1 &gt; $1' -- {}
</code></pre>

<p>Courtesy to <a href="https://stackoverflow.com/questions/845863/how-to-use-in-an-xargs-command">this answer</a> </p>
