title: Removing portions of .tgz filename and moving into newly created directories, then extract. Bash Shell
body: <p>I have done some searching around but couldn't find something that really helped what I needed.</p>
  
  <p>I am trying to rename all .tgz files in dir, create dirs using new filenames,and mv all .tgz files to new directories using shell/bash.</p>
  
  <hr>
  
  <p>Example:</p>
  
  <p>INITIAL STATE: </p>
  
  <pre><code>data/results/
      test_a.1.0.11.class.tgz
      test_b.1.0.12.class.tgz
      test_c.1.0.13.class.tgz
      test_d.1.0.14.class.tgz
      test_d.1.0.15.class.tgz
  </code></pre>
  
  <p>RESULT STATE:</p>
  
  <pre><code>data/compared/1.0.11to1.0.12/
        1.0.11.class.tgz
        1.0.12.class.tgz
  
  data/compared/1.0.12to1.0.13/
        1.0.12.class.tgz
        1.0.13.class.tgz
  
  data/compared/1.0.13to1.0.14/
        1.0.13.class.tgz
        1.0.14.class.tgz
  
  data/compared/1.0.14to1.0.15/
        1.0.14.class.tgz
        1.0.15.class.tgz
  </code></pre>
  
  <p>Also, having part of the script that will extract all .tgz tarfiles in same final directory would be great.</p>
  
  <p>Example:</p>
  
  <p>data/compared/1.0.14to1.0.15/
        1.0.14.class.tgz
        1.0.15.class.tgz
        /extractedTar1.0.14
        /extractedTar1.0.15</p>
  
  <p>Thanks a ton, all!</p>
  
  <hr>
  
  <p>What I've tried so far:</p>
  
  <h1>!/bin/bash</h1>
  
  <pre><code>for full_filename in *.tgz; do
      extension="$full_{filename##*.}"
      filename="$full_filename%.*}"
      mkdir -p "$filename"
      mv "$full_filename" "$filename/"
  done
  </code></pre>
  
  <p>As you can see this doesn't do exactly what I want at all.</p>
  
  <hr>
  
  <hr>
  
  <p>EDIT: Extra functionality request!
  The tarballs each consist of a single(/test) directory which houses many other dir/files. 
  E.g. 1.0.11.class.tgz consists of a respective"/test" directory. </p>
  
  <p>Is there a way to extract each of these tarballs, being careful to rename the extracted /"test" directory to something like "test_1.0.11" before accidentally extracting the other tarball into the same "/test" directory? Thanks a ton! </p>