title: Bash - filter files in the folder
body: <p>So I have this problem: I have a folder in my Ubuntu which contains log files. The naming pattern of all files is as following:</p>
  
  <p>d<strong>1</strong>.exert.<strong>de</strong>-access.log-<strong>2016-06-28</strong></p>
  
  <p>There are plenty of files. I highlighted with bold what part of the name can vary. There are always two files for specific date and domain (.de, .co.uk, .dk etc.), one of which is prefixed with d1 ane the other one with d2. I need to concat d1 and d2 files for each date and domain, for example:</p>
  
  <pre><code>1) d1.exert.de_access.log_2016-06-28
  2) d1.exert.dk_access.log_2016-06-24
  3) d1.exert.dk_access.log_2016-06-25
  4) d2.exert.de_access.log_2016-06-28
  5) d2.exert.dk_access.log_2016-06-24
  6) d2.exert.dk_access.log_2016-06-25
  </code></pre>
  
  <p>I need to pair and concat files: 1) and 4), 2) and 5), 3) and 6) because they have the same domain and date, but different prefixes.</p>
  
  <p>So I need to go through all files in the folder and find these d1/d2 pairs for every date and domain. Then I have to concat these pairs. I need to write a script that will automatically find these pairs. I thought about some sort of double loop (e. g. the outer one searches date, and the inner one searches for domain) but I don't have idea how to achieve it. Or maybe there is some easier solution?</p>