Scripting with Go (2022)
Every time I see things like this, I feel like the person must be unaware of awk.<p><pre><code>  # the original one-liner to get unique IP addresses
  cut -d&#x27; &#x27; -f 1 access.log | sort | uniq -c | sort -rn | head
  # turns into this with GNU awk
  gawk &#x27;{PROCINFO[&quot;sorted_in&quot;] = &quot;@val_num_desc&quot;; a[$1]++} END {c=0; for (i in a) if (c++ &lt; 10) print a[i], i}&#x27; access.log
</code></pre>
It&#x27;s also far, far faster on larger files (base-spec M1 Air):<p><pre><code>   $ wc -lc fake_log.txt
   1000000 218433264 fake_log.txt

  $ hyperfine &quot;gawk &#x27;{PROCINFO[\&quot;sorted_in\&quot;] = \&quot;@val_num_desc\&quot;; a[\$1]++} END {c=0; for (i in a) if (c++ &lt;10) print a[i], i}&#x27; fake_log.txt&quot;
  Benchmark 1: gawk &#x27;{PROCINFO[&quot;sorted_in&quot;] = &quot;@val_num_desc&quot;; a[$1]++} END {c=0; for (i in a) if (c++ &lt;10) print a[i], i}&#x27; fake_log.txt
  Time (mean ± σ):      1.250 s ±  0.003 s    [User: 1.185 s, System: 0.061 s]
  Range (min … max):    1.246 s …  1.254 s    10 runs

  $ hyperfine &quot;cut -d&#x27; &#x27; -f1 fake_log.txt | sort | uniq -c | sort -rn | head&quot;
  Benchmark 1: cut -d&#x27; &#x27; -f1 fake_log.txt | sort | uniq -c | sort -rn | head
  Time (mean ± σ):      4.844 s ±  0.020 s    [User: 5.367 s, System: 0.087 s]
  Range (min … max):    4.817 s …  4.873 s    10 runs
</code></pre>
Interestingly, GNU cut is significantly faster than BSD cut on the M1:<p><pre><code>  $ hyperfine &quot;gcut -d&#x27; &#x27; -f1 fake_log.txt | sort | uniq -c | sort -rn | head&quot;
  Benchmark 1: gcut -d&#x27; &#x27; -f1 fake_log.txt | sort | uniq -c | sort -rn | head
  Time (mean ± σ):      3.622 s ±  0.004 s    [User: 4.149 s, System: 0.078 s]
  Range (min … max):    3.616 s …  3.629 s    10 runs</code></pre>