pipr.tools

count

Count occurrences of each unique line

Aa Text

Try it

stdin0 chars
stdout0 chars

Example

Count occurrences of each log level

Usage
$ echo "error
info
error
warn
info
error
info
info" | count
View source
(input) => {
      const freq = {};
      for (const line of input.split("\n")) freq[line] = (freq[line] || 0) + 1;
      return Object.entries(freq)
        .sort((a, b) => b[1] - a[1])
        .map(([val, n]) => `${n}\t${val}`)
        .join("\n");
    }

Suggested Pipelines

Related Tools