title: OS X - Batch add prefix to files depending on filename length
body: <p>I have a textlist with thousands of psd files which all have either 7 or 8 digits in front of the first underscore seperator in the filename. </p>
  
  <p>Depending on the number of digits I need to prefix the file with either "X0" (7 digits) or Y (8 digits) so I end up with files which have identical lengths before the first underscore.</p>
  
  <p>Example:</p>
  
  <pre><code>&lt;br /&gt;0123456_this_is_file_1.psd
  &lt;br /&gt;0654321_this_is_file_2.psd
  &lt;br /&gt;30301234_this_is_file_3.psd
  &lt;br /&gt;50509876_this_is_file_4.psd
  </code></pre>
  
  <p>After the prefix addition the filename would be like this:</p>
  
  <pre><code>&lt;br /&gt;X00123456_this_is_file_1.psd
  &lt;br /&gt;X00654321_this_is_file_2.psd
  &lt;br /&gt;Y30301234_this_is_file_3.psd
  &lt;br /&gt;Y50509876_this_is_file_4.psd
  </code></pre>
  
  <p><strong>How can this be done in a shell script (OS X Sierra)?</strong></p>