title: sort and get unique files after removing extension of filename
body: <p>I am trying to remove filename after the second underscore and get the unique files. I saw many answers and formed a script. This script is working fine till the cut command but it is not able to give the unique filenames.  I have tried the following command but i am not getting desired output.</p>
  <p>script used:</p>
  <pre><code> for filename in ${path/to/files}/*.gz; 
      do
      fname=$(basename ${filename} | cut -f 1-2 -d &quot;_&quot; | sort | uniq)
  echo &quot;${fname}&quot;
      done
  </code></pre>
  <p>file example:</p>
  <ol>
  <li>filename1_00_1.gz</li>
  <li>filename1_00_2.gz</li>
  <li>filename2_00_1.gz</li>
  <li>filename2_00_2.gz</li>
  </ol>
  <p>Required output:</p>
  <ol>
  <li>filename1_00</li>
  <li>filename2_00</li>
  </ol>
  <p>So, with all of that said. how can I get a unique list of files in the required output format?
  Thanks a lot in advance.</p>