title: Shell Removing part of a string with sed
body: <p>Good day.</p>
  
  <p>I actually have 2 questions that are related to the sed command in shell and they are very similar.</p>
  
  <p>The first question is how to use sed to get a file name and remover part of it's name like the example below:</p>
  
  <p>Original file:</p>
  
  <p>BAT_MAN_T_spades_proc_whatever_t6_12345_14785963214785_12345.txt</p>
  
  <p>What i want the file name to look like:</p>
  
  <p>BAT_T_spades_proc_whatever_t6_12345_14785963214785_12345.txt</p>
  
  <p>I just want the "MAN" part after the first underline to be removed out of the original file  name.</p>
  
  <p>The second question is about the following sed command that I've found on a file a while ago:</p>
  
  <pre><code>random_string_var_name=$(echo $file_name | sed -r 's/^[^_]*_[^_]*_(.*_t[0-9]{1}).*(_[0-9]*)\.txt/_\1\2/')
  </code></pre>
  
  <p>this pretty much get parts of a file name a saves it on a variable, like the example bellow:</p>
  
  <p>Name of the file:</p>
  
  <pre><code>BAT_MAN_T_spades_proc_whatever_t6_12345_14785963214785_12345.txt
  </code></pre>
  
  <p>What that sed command gets:</p>
  
  <pre><code>T_spades_proc_whatever_t6_12345
  </code></pre>
  
  <p>I got what it does but i don't understand how that command works, so i would like to understand that.</p>