title: Convert power shell script to bash script to rename multiple file names
body: <p>This is my first post and I'm sure it will reveal how new I am with all this, but I would really appreciate any help I can get.</p>
  <p>I have a power shell script that renames multiple file names that needs to be converted to bash. I have changed some of the data to conceal the nature of it, so hopefully that doesn't mess anything up.</p>
  <p>I essentially want to go from this file name:</p>
  <pre><code>SSS&amp; Onboarding - Individual Ad HocSegments (13).tsv 
  </code></pre>
  <p>to this file name:</p>
  <pre><code>SSSOnboarding_Individual_Ad_HocSegments_20210706.tsv
  </code></pre>
  <p>Power shell script</p>
  <pre><code>Dir SS* | Rename-Item -NewName {$_.name -replace &quot;SSS&amp; Onboarding - &quot;,&quot;SSSOnboarding-&quot;}
  
  Dir SS* | Rename-Item -NewName {$_.name -replace &quot;SSS Measurement - &quot;,&quot;SSSMeasurement-&quot;}
  
  Dir SS* | Rename-Item -NewName {$_.name -replace &quot;.tsv&quot;,&quot;_&quot; }
  
  Dir SS* | Rename-Item -NewName {$_.name -replace &quot; &quot;,&quot;_&quot; }
  
  Dir SS* | Rename-Item -NewName {$_.name -replace &quot;_-_&quot;,&quot;_&quot;}
  
  Dir SS* | %{rename-item $_.name (( $_.name.split(&quot;(&quot;))[0]+$_.LastWriteTime.toString(&quot;yyyyMMdd&quot;)+&quot;.tsv&quot;) }
  </code></pre>
  <p>Here is what I have tried so far.</p>
  <pre><code>  rename &quot;SSS&amp; Onboarding -&quot; SSSOnboarding SS*
    rename &quot;SSS&amp; Measurement -&quot; SSSMeasurement SS*
    rename &quot;.tsv&quot; &quot;_&quot; SS*
    rename &quot; &quot; &quot;_&quot; SS*
    rename &quot;-&quot; &quot;_&quot; SS*
    
    ls -1 SS* | while read FILE
      do
          new_file=`echo $FILE | cut -d'(' -f1``date +'%Y%m%d'`'.tsv'
          echo $new_file
          mv $FILE $new_file
          
       done
  </code></pre>
  <p>This is what is returned:</p>
  <pre><code>SSSOnboarding_Individual Ad HocSegments (17)_
  </code></pre>
  <p>The bottom part, starting at ls -1 | while read FILE, messes everything up, but everything above it works. Before I added the bottom part, the renames replaced all spaces and dashes with underscores as desired.</p>
  <p>Thank you!!</p>