title: How to read out a file line by line and for every line do a search with find and copy the search result to destination?
body: <p>I hope you can help me with the following problem:</p>
  <p><strong>The Situation</strong></p>
  <ul>
  <li>I need to find files in various folders and copy them to another folder. The files and folders can contain white spaces and umlauts.</li>
  <li>The filenames contain an ID and a string like:
  &quot;2022-01-11-02 super important file&quot;</li>
  <li>The filenames I need to find are collected in a textfile named ids.txt. This file only contains the IDs but not the whole filename as a string.</li>
  </ul>
  <p><strong>What I want to achieve:</strong></p>
  <ul>
  <li>I want to read out ids.txt line by line.</li>
  <li>For every line in ids.txt I want to do a <code>find</code> search and copy <code>cp</code> the result to destination.</li>
  </ul>
  <p>So far I tried:</p>
  <ul>
  <li><code>for n in $(cat ids.txt); do find /home/alex/testzone/ -name &quot;$n&quot; -exec cp {} /home/alex/testzone/output \; ;</code></li>
  <li><code>while read -r ids; do find /home/alex/testzone -name &quot;$ids&quot; -exec cp {} /home/alex/testzone/output \; ; done &lt; ids.txt</code></li>
  </ul>
  <p>The output folder remains empty. Not using <code>-exec</code> also gives no (search)results.</p>
  <p>I was thinking that <code>-name &quot;$ids&quot;</code> is the root cause here. My files contain the ID + a String so I should search for names containing the <strong>ID</strong> plus a <strong>variable string (star)</strong></p>
  <ul>
  <li>As argument for <code>-name</code> I also tried <code>&quot;$ids *&quot;</code> <code>&quot;$ids&quot;&quot; *&quot;</code> and so on with no luck.</li>
  </ul>
  <p>Is there an argument that I can use in conjunction with find instead of using the star in the <code>-name</code> argument?</p>
  <hr />
  <p><strong>Do you have any solution for me to automate this process in a bash script to read out ids.txt file, search the filenames and copy them over to specified folder?</strong></p>
  <p><strong>In the end I would like to create a bash script that takes ids.txt and the search-folder and the output-folder as arguments like:</strong></p>
  <pre><code>my-id-search.sh /home/alex/testzone/ids.txt /home/alex/testzone/ /home/alex/testzone/output 
  </code></pre>
  <hr />
  <p><strong>EDIT:</strong>
  This is some example content of the ids.txt file where only ids are listed (not the whole filename):</p>
  <pre><code>2022-01-11-01
  2022-01-11-02
  2020-12-01-62
  </code></pre>
  <p><strong>EDIT II:</strong>
  Going on with the solution from tripleee:</p>
  <pre><code>#!/bin/bash
  
  grep . $1 | while read -r id; do
  echo &quot;Der Suchbegriff lautet:&quot;$id; echo;
     find /home/alex/testzone -name &quot;$id*&quot; -exec cp {} /home/alex/testzone/ausgabe \;
  done
  </code></pre>
  <p>In case my ids.txt file contains empty lines the <code>-name &quot;$id*&quot;</code> will be <code>-name *</code> which in turn finds all files and copies all files.</p>
  <p>Trying to prevent empty line to be read does not seem to work. They should be filtered by the expression <code>grep . $1 |</code>. What am I doing wrong?</p>