title: Arranging files into folders with python or bash?
body: <p>So I have a bunch of files I want to sort into folders. The nameing scheme is as follows:</p>
  
  <pre><code>text_1_text_-66_text_.mrc
  text_1_text_-63_text_.mrc
  text_1_text_-60_text_.mrc
  text_1_text_-57_text_.mrc
  text_2_text_-66_text.mrc
  text_2_text_-63_text.mrc
  text_2_text_-60_text.mrc
  </code></pre>
  
  <p>and so on (the actual number of files is plus to minus 66 so text_1 has a lot more for example). I want to sort by the first number (so the 1 in text_1_...) I have a script that I used to previously sort files:</p>
  
  <pre><code>import os
  import shutil
  
  n = 1
  
  while (n &lt; 500):
      if os.path.isfile('Stack_%d.txt' % (n)): 
          directory = 'Stack_%d' % (n)
          os.makedirs(directory)
          shutil.move('Stack_%d.txt' % (n), 'stack_%d' % (n))
          shutil.move('Stack_%d_shifts.txt' % (n), 'stack_%d' % (n))
          shutil.move('Stack_%d.mrc' % (n), 'stack_%d' % (n))
          shutil.move('Stack_%d.rawtlt' % (n), 'stack_%d' % (n))
      else:
          n = n+1
  </code></pre>
  
  <p>This is a bit crude but worked fine to sort those files. In an ideal world I would like to just know a command similar to * in bash that means I can just use string substitution for the beginning of each and then * the rest of the quote. </p>
  
  <p>Sorry I am pretty new to programming and all my use cases seem to be small scripts so getting there slowly. </p>