title: How can I make a bash script where I can move certain files to certain folders which are named based on a string in the files?
body: <p>This is the script that I'm using to move files with the string &quot;john&quot; in them (124334_john_rtx.mp4 , 3464r64_john_gty.mp4 etc) to a certain folder</p>
  <pre><code>find /home/peter/Videos -maxdepth 1 -type f -iname '*john' -print0 | \
  xargs -0 --no-run-if-empty echo mv --target-directory=/home/peter/Videos/john/
  </code></pre>
  <p>Since I have a large amount of videos with various names written in the files, I want to make a bash script which moves videos with a string between the underscores to a folder named based on the string between the underscores. So for example if a file is named 4345655_ben_rts.mp4 the script would identify the string &quot;ben&quot; between the underscores, create a folder named as the string between the underscores which in this case is &quot;ben&quot; and move the file to that folder. Any advice is greatly appreciated !</p>