title: Filter files using regular expressions with sed in unix
body: <p>im documenting a Shell Script of the server of my job which takes a series of files that starts with the word "dat" and performs a particular task with all those files. The problem is that the script is filtering files using a regular expression with sed command as follows:</p>
  
  <pre><code>namecmp=`grep -l $name dat*.p |sed -e "s/^\(......\)\(..\)\(..\)\(....\)\(.*\)/\1\4\3\2\5/g"| sort -t '.' -k 1.7,1.14 |sed -e "s/^\(......\)\(....\)\(..\)\(..\)\(.*\)/\1\4\3\2\5/g" | tail -1 `
  </code></pre>
  
  <p>I don't understand how exactly is doing this regular expression to filter out files. It would be helpful to know any expected output or examples files filtered by that expression. </p>
  
  <p>Is there a way to find possible expressions that are accepted by that expression?</p>