title: Bash or Awk Script to Merge Lines Where X Number of Fields Match While Creating Ranges in Fields that Don't Match
body: <p><strong>NEED</strong>:  I have a file containing data like the sample below.  I need to:</p>
  
  <ol>
  <li>Merge all lines into one line when X number of fields match</li>
  <li>Create range of values in X number of fields when the values vary</li>
  </ol>
  
  <p><em>In this case:
  Merge all lines into one where <strong>fields $1 through $6 and $8 match</strong>, create a range of the associated values in field <strong>$7</em></strong></p>
  
  <p>OR</p>
  
  <p>Merge all lines into one where <strong>fields $1 through $7</strong> match, create a range of the associated values in field <strong>$8*</strong></p>
  
  <ol start="3">
  <li>The solution has to be something native to Linux (like a bash or awk script) that doesn't require installation of additional software (e.g. datamash).</li>
  </ol>
  
  <p><em>@rtx13's solution below using TCL does work (thanks again), I'm just not sure if I can install TCL in my live environment so I hope and AWK/BASH/etc. solution can also be proposed.</em></p>
  
  <p><strong>Original data:</strong></p>
  
  <pre><code>HOST    FILTER  INTERFACE   SOURCE  DESTINATION PROTOCOL    SOURCE PORT DESTINATION PORT
  host1   input   nic1        ip1     ip2         PROT        30000       10
  host1   input   nic1        ip1     ip2         PROT        50000       10
  host1   input   nic1        ip1     ip2         PROT        60000       10
  host1   input   nic1        ip3     ip2         PROT        10          30000
  host1   input   nic1        ip3     ip2         PROT        10          50000
  host1   input   nic1        ip3     ip2         PROT        10          60000
  host1   output  nic1        ip2     ip1         PROT        10          30000
  host1   output  nic1        ip2     ip1         PROT        10          50000
  host1   output  nic1        ip2     ip1         PROT        10          60000
  host1   output  nic1        ip2     ip3         PROT        30000       10
  host1   output  nic1        ip2     ip3         PROT        60000       10
  host1   output  loc         ip2     ip2         PROT        10          30000
  host1   output  loc         ip2     ip2         PROT        10          50000
  </code></pre>
  
  <p><strong>Desired Processed Output:</strong></p>
  
  <pre><code>host1   input   nic1        ip1     ip2         PROT        30000:60000 10
  host1   input   nic1        ip3     ip2         PROT        10          30000:60000
  host1   output  nic1        ip2     ip1         PROT        10          30000:60000
  host1   output  nic1        ip2     ip3         PROT        30000:60000 10
  host1   output  loc         ip2     ip2         PROT        10          30000:50000
  </code></pre>
  
  <p>Do I need a separate file that lists the ports I'd like to merge on?  Since these could also fall inside a range as well?  So the script could reference it to know whether it's a merge port or not?</p>
  
  <pre><code>10|EXAMPLE
  22|SSH
  80|HTTP
  2049|NFS
  *etc*
  </code></pre>
  
  <p>I'm trying to be as specific as I can be since my original post was deemed to need more focus; it received an answer (Thanks you @Enrico Maria De Angelis) that was close, but not quite all the way there as well as one that used datamash (Thank you @oguz ismail), which worked great but sadly I need a solution not requiring installation of additonal software:
  <a href="https://stackoverflow.com/questions/60895489/merge-all-lines-that-are-identical-aside-from-a-key-field-and-make-key-field-a-r">Merge all lines that are identical aside from a key field and make key field a range</a></p>