Comment

Comment by aozgaa

Another solution to the pipeline example, this time making use of a subprogram for the frequency/accumulation:

    < README.md \
      tr -c '[:alpha:]' '\n' \
    | tr '[:upper:]' '[:lower:]' \
    | awk '
        NF {
          if (!($0 in count)) order[++n] = $0
          count[$0]++
        }
        END {
          for (i = 1; i <= n; i++) {
            print count[order[i]], order[i]
          }
        }
    '
If you don't allow `awk` in your "pure bash" then ofc this is not satisfactory. But it has the upside that the associative arrays are pretty explicit data structures (for the ordering and counts, respectively).
parent aozgaa 1 month ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton