pipr.tools

sort-lines

Sort lines alphabetically

Aa Text

Try it

stdin0 chars
stdout0 chars

Flags

--reverse boolean default: false
--numeric boolean default: false

Example

Sort a list of fruits alphabetically

Usage
$ echo "banana
apple
cherry
date
apricot" | sort-lines
View source
(input, opts = {}) => {
      const lines = input.split("\n");
      if (opts.numeric) lines.sort((a, b) => parseFloat(a) - parseFloat(b));
      else lines.sort((a, b) => a.localeCompare(b));
      if (opts.reverse) lines.reverse();
      return lines.join("\n");
    }

Suggested Pipelines

Related Tools