title: Bash - Renaming files with prefix before moving to single folder
body: <p>Using bash how can I find all files in subdirectories with extension .txt, prefix the name with the directory name? Then move all those .txt files to a single folder in the current directory?</p>
  
  <p>Example:  </p>
  
  <pre><code>\subdirectory1\result1.txt  
  \subdirectory1\result2.txt  
  \subdirectory2\result1.txt  
  \subdirectory2\result2.txt  
  \subdirectory3\result1.txt  
  \subdirectory3\result2.txt  
  </code></pre>
  
  <p>I want to copy and prefix .txt files with the directory name and place them in a new directory such that the result is:</p>
  
  <pre><code>\newfolder\subdirectory1_result1.txt  
  \newfolder\subdirectory1_result2.txt    
  \newfolder\subdirectory2_result1.txt    
  \newfolder\subdirectory2_result2.txt    
  \newfolder\subdirectory3_result1.txt  
  \newfolder\subdirectory3_result2.txt
  </code></pre>