title: Shell Script to find JPG and MOV files
body: <p><strong>Background</strong></p>
  <p>iPhone has live photo's, i thought i could use VLC on Windows or some iPhone app to take a still of the desired frame. Long story short, you can but the quality of the image as well as the resolution is drastically lowered. So i gave up on this.</p>
  <p><strong>Problem</strong></p>
  <p>I have actual movie files hidden along side the Live Photo's</p>
  <p><strong>My Goal</strong></p>
  <p>Using cygwin to run a bash shell script to iterate through 0000 to 9999 and find all JPG and MOV files that have the same name ONLY.</p>
  <p><strong>Problem</strong></p>
  <p>I am having issues with the <code>regex</code></p>
  <p>I tried <code>ls | grep -E &quot;IMG_0016\.(JPG|MOV)&quot;</code></p>
  <p>I need a bash script that will return true if it finds <strong>both</strong> a jpg and mov file for the given filename. Is this doable in a one liner? Can anyone give me some ideas on how to make the above bash command more robust?</p>
  <p>It finds both but how do i say, okay, good job, you have both, now do the following with those two files.</p>
  <p><strong>EDIT</strong></p>
  <h1>!/bin/bash</h1>
  <pre><code>for i in $(seq -f &quot;%04g&quot; 0 20)
  do
    FILENAME=&quot;IMG_$i&quot;
    #echo &quot;$FILENAME&quot;
    var=$(ls -l | grep &quot;$FILENAME&quot; | grep -E &quot;(JPG|MOV)&quot; | wc -l)
    if [ &quot;$var&quot; == 2 ] ; then
      echo we found both for $FILENAME
      echo $var
    fi
  done
  </code></pre>
  <p><strong>Output</strong></p>
  <pre><code>we found both for IMG_0018
  2
  we found both for IMG_0019
  2
  </code></pre>
  <p><strong>EXPECTED</strong></p>
  <p>files in directory are:</p>
  <ul>
  <li>IMG_0016.JPG</li>
  <li>IMG_0018.JPG</li>
  <li>IMG_0018.MOV</li>
  <li>IMG_0019.JPG</li>
  <li>IMG_0019.MOV</li>
  </ul>
  <p><strong>COMMENT</strong></p>
  <p>This is good in the sense that it looks for only 2 files but there has to be a better way to say find <strong>ONE</strong> JPG and <strong>ONE</strong> MOV??</p>
  <p><strong>EDIT 2</strong></p>
  <pre><code>#!/bin/bash
  
  for i in $(seq -f &quot;%04g&quot; 0 20)
  do
    FILENAME=&quot;IMG_$i&quot;
    #echo &quot;$FILENAME&quot;
    var=$(ls -l | grep &quot;$FILENAME&quot; | grep -E &quot;(JPG|MOV)&quot; | wc -l)
    #echo $var
    if [ &quot;$var&quot; == 2 ] ; then
      #echo we found both for $FILENAME
      var=$(ls -l | grep &quot;$FILENAME&quot; | grep -E JPG | wc -l)
      if [ &quot;$var&quot; == 1 ] ; then
        var=$(ls -l | grep &quot;$FILENAME&quot; | grep -E MOV | wc -l)
        if [ &quot;$var&quot; == 1 ] ; then
          mv &quot;D:\Mike\Pictures\TEST\\$FILENAME.JPG&quot; &quot;D:\Mike\Pictures\TEST\MATCH\\$FILENAME.JPG&quot;
          mv &quot;D:\Mike\Pictures\TEST\\$FILENAME.MOV&quot; &quot;D:\Mike\Pictures\TEST\MATCH\\$FILENAME.MOV&quot;
        fi
      fi
    fi
  done
  </code></pre>