title: How to sort lines by regex with sed
body: <p>I am trying to sort lines in file by matching regex in column2 (ending TLD) using <code>sed</code>.</p>
  
  <p>This is an example file:</p>
  
  <pre><code>server7, server.com,someval
  server6, server.com, someval
  server4, server.uk, someval
  server2, server.com, someval
  server10, server.us, someval
  server7, server.uk, someval
  server10, server.uk, someval
  server10, server.us, someval
  </code></pre>
  
  <p>I've tried with:</p>
  
  <pre><code>sed -r "s/(.*\.com.*)|(.*\.uk.*)|(.*\.us.*)/\3\2\1/g" file
  </code></pre>
  
  <p>But that reproduce the same output, making no changes.</p>
  
  <p>I want my file to be sorted like:</p>
  
  <pre><code>server7, server.com,someval
  server6, server.com, someval
  server2, server.com, someval
  server10, server.us, someval
  server7, server.uk, someval
  server10, server.uk, someval
  server10, server.us, someval
  server10, server.us, someval
  </code></pre>
  
  <p>Thank you for help.</p>