title: Get unique string occurrence and display it
body: <p>I'm not really good with <code>awk</code>, so here what I just did to count the number occurence in one row:</p>
  <p>the input.txt has this:</p>
  <pre><code>18 18 21 21 21 21 18 21
  </code></pre>
  <p>I just want to display the unique number that occur above. So, here is my code:</p>
  <pre><code>input=&quot;input.txt&quot;
  
  output=$(fmt -1 &quot;$input&quot; | sort | uniq | awk '{printf $1&quot;,&quot;}')
  
  echo &quot;$output&quot;
  </code></pre>
  <p>The output:</p>
  <pre><code>18,21,
  </code></pre>
  <p>I got the result correctly but that comma <code>,</code> at the end, how do I remove that comma? Also, is there a simpler or a clean method without using <code>fmt</code> ?</p>
  <p>The expected output:</p>
  <pre><code>18,21
  </code></pre>
  <p>Edit to remove comma, I use this:</p>
  <p><code>sed 's/,$//'</code></p>
  <p>and it's working, but is there a simpler way to do this without using <code>fmt</code> ?</p>