title: One liner for using xargs to grep output of one command on a search text produced by other command
body: <p>I am trying to accomplish the following in one line:</p>
  
  <pre><code>&lt;command&gt; | xargs -I {} grep {} &lt;(other command)&gt;
  </code></pre>
  
  <p>I have a Kubernetes cluster which is running Redis and many other applications. I want to find out which applications (pods in this case) are connected to Redis. </p>
  
  <p>This can be broken down in two steps. </p>
  
  <ul>
  <li>Getting the list of IPs connected to Redis.</li>
  <li>Get the pod names that holds those IPs.</li>
  </ul>
  
  <p>I got the list of IPs with the following command:</p>
  
  <pre><code>$ kubectl exec -it redis -- redis-cli -a &lt;redis-auth&gt; client list | tail -n +2 | awk -F '[:= ]' '{ print $4 }' | sort | uniq &gt; test.txt
  $ cat test.txt
  10.52.1.194
  10.52.1.91
  10.52.2.44
  10.52.3.223
  127.0.0.1
  </code></pre>
  
  <p>And I can also get the pod names with the following command:</p>
  
  <pre><code>$ grep -f test.txt &lt;(kubectl get pods -o wide)
  app1              1/1     Running     0          9d      10.52.1.91    node-8    &lt;none&gt;           &lt;none&gt;
  app2              2/2     Running     0          79d     10.52.2.44    node-14   &lt;none&gt;           &lt;none&gt;
  app3              2/2     Running     2          79d     10.52.1.194   node-11   &lt;none&gt;           &lt;none&gt;
  app4              1/1     Running     0          5d10h   10.52.3.223   node-30   &lt;none&gt;           &lt;none&gt;
  </code></pre>
  
  <p>I want to accomplish both of these in one line. I tried the following:</p>
  
  <pre><code>$ kubectl exec -it redis -- redis-cli -a &lt;redis-auth&gt; client list | tail -n +2 | awk -F '[:= ]' '{ print $4 }' sort | uniq | xargs -t -I{} grep {} &lt;(kubectl get pods -o wide)
  </code></pre>
  
  <p>it prints the following commands (that should be performed) but only performs the the first command:</p>
  
  <pre><code>grep 10.52.1.194 /dev/fd/63
  app3              2/2     Running     2          79d     10.52.1.194   node-11   &lt;none&gt;           &lt;none&gt;
  grep 127.0.0.1 /dev/fd/63
  grep 10.52.1.91 /dev/fd/63
  grep 10.52.2.44 /dev/fd/63
  grep 10.52.3.223 /dev/fd/63
  </code></pre>
  
  <p>How can I accomplish this in one line. Also, I am aware that I can give an <code>name</code> to each client that is connecting to Redis but it requires changing the application code which I can't do right now.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>The one-liner given by me actually partially works as in it only performs the first <code>grep ...</code> instead of all the <code>grep ...</code> commands. Can anyone explain what am I doing wrong here?</p>
  
  <p><strong>Edit2:</strong></p>
  
  <p>My hypothesis that only the first grep command works is that somehow after the first grep command, <code>/dev/fd/63</code> probably points to a non-existing or empty file. Also, the following command works for some reason. Can anyone explain?</p>
  
  <pre><code>$ kubectl exec -t redis -- redis-cli -a &lt;redis-auth&gt; client list | tail -n +2 | awk -F '[:= ]' '{ print $4 }' | sort -u | xargs -t -I{} bash -c 'grep -w {} &lt;(kubectl get pods -o wide)'
  bash -c grep -w 10.52.1.194 &lt;(kubectl get pods -o wide)
  app3                 2/2     Running     2          80d     10.52.1.194   node-11   &lt;none&gt;           &lt;none&gt;
  bash -c grep -w 10.52.1.91 &lt;(kubectl get pods -o wide)
  app1                 1/1     Running     0          10d     10.52.1.91    node-8    &lt;none&gt;           &lt;none&gt;
  bash -c grep -w 10.52.2.44 &lt;(kubectl get pods -o wide)
  app2                 2/2     Running     0          80d     10.52.2.44    node-14   &lt;none&gt;           &lt;none&gt;
  bash -c grep -w 10.52.3.223 &lt;(kubectl get pods -o wide)
  app4                 1/1     Running     0          6d10h   10.52.3.223   node-30   &lt;none&gt;           &lt;none&gt;
  </code></pre>