title: Capture part of name so that I can loop in linux
body: <p>how do i capture a pattern in a filename and use that to do in linux?</p>
  
  <p>example in a folder contains these files:<br>
  <code>BBB137O19_rc.fa
  BBB921N08_cleaned.fa
  BBB002O19_cc.fa</code></p>
  
  <p>I would like to capture the front part of the filename and use that to do things like renaming, run a program etc. Apparently, basename is greedy and works for everything before the extension.</p>
  
  <p>thanks in advance</p>
  
  <p>I tried this command but failed<BR>
  <code>for i in *.fa; base=$(basename $i _*.fa); comb="${base}_ec.txt"; mv ec.txt $comb; done</code></p>