title: Bash: pass multiline output of grep to another command that loops
body: <p>I have the following command to grep the kafka topics </p>
  
  <pre><code>kafka-topics --list --zookeeper localhost:2181 | grep repartition
  </code></pre>
  
  <p>This give me a shell output with multiple topics </p>
  
  <pre><code>dev-ALPHA_CLUSTER-investment.ed.store.alpha_cluster-repartition
  dev-CUSTOM_GROUP-KSTREAM-REDUCE-STATE-STORE-0000000003-repartition
  dev-CUSTOM_GROUP-investment.ed.store.custom_group-repartition
  </code></pre>
  
  <p>I need to provide these topics one by one to another command</p>
  
  <pre><code>kafka-topics --zookeeper localhost:2181 --alter --config cleanup.policy=compact --topic TOPIC_NAME
  </code></pre>
  
  <p>where <code>TOPIC_NAME</code> is the topic(s) from the previous grep command. I was wondering if there is a way to combine them such that if the grep has some results (topics separated by newline) then the other command is executed in a loop with <code>TOPIC_NAME</code> being each topic returned by grep</p>