<p>Is it possible to use pipe output as input for grep or git grep? The data im trying to pass to grep/git grep is the following</p>
<pre><code>    kubectl get namespace -o name -l app.kubernetes.io/instance!=applications | cut -f2 -d &quot;/&quot; 
argocd
default
kube-node-lease
kube-public
kube-system
nsx-system
pks-system
</code></pre>
<p>I've tried to extent the command but this results in an error:</p>
<pre><code>   kubectl get namespace -o name -l app.kubernetes.io/instance!=applications | cut -f2 -d &quot;/&quot; | xargs git grep -i
fatal: ambiguous argument 'default': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git &lt;command&gt; [&lt;revision&gt;...] -- [&lt;file&gt;...]'
</code></pre>
<p>Using just grep results in:</p>
<pre><code>    kubectl get namespace -o name -l app.kubernetes.io/instance!=applications | cut -f2 -d &quot;/&quot; | xargs grep -i
grep: default: No such file or directory
grep: kube-node-lease: No such file or directory
grep: kube-public: No such file or directory
grep: kube-system: No such file or directory
grep: nsx-system: No such file or directory
grep: pks-system: No such file or directory
</code></pre>
<p>The issue im facing with grep in general in this particular case is, that even if i soley use grep within my directory, it takes ages till it's done, whereas git grep is done within seconds. If I'm not doing something terrible wrong that would explain the slow results of grep, getting git grep to work would be preferred.</p>
<p>I've found this other Stackoverflow <a href="https://stackoverflow.com/questions/9754236/git-grep-gives-unknown-revision-or-path-not-in-the-working-tree">Question</a> that somewhat explains what the issue is, but I don't know how to &quot;process&quot; the output into git grep properly.</p>

<p>The problem is that (as your screenshot shows) the result is multiple terms which I'm guessing you want to be <em>OR</em>-ed together, and not searching for the first term in the files identified by the last terms (which is what the current xargs command does)</p>
<p>Since OR in regex is via the <code>|</code> character, you can use <code>xargs echo</code> to fold the vertical list into a space delimited horizontal list then replace the spaces with <code>|</code> and be pretty close to what you want</p>
<pre class="lang-sh prettyprint-override"><code>printf 'alpha\nbeta\ncharlie\n' | xargs echo | tr ' ' '|' | xargs git grep -i
</code></pre>
<p>although due to the folding operation, that command is an xargs of one line, and thus would be conceptually easier to reason about using just normal <code>$()</code> interpolation:</p>
<pre class="lang-sh prettyprint-override"><code>git grep -i $(printf 'alpha\nbeta\ncharlie\n' | xargs echo | tr ' ' '|')
</code></pre>
<p>The less &quot;whaaa&quot; shell pipeline would be to use <code>kubectl get -o go-template=</code> to actually emit a pipe-delimited list and feed that right into xargs (or <code>$()</code>), bypassing the need to massage the output text first</p>
