1

Sort and remove duplicate lines in a file in one step without intermediary files

vi +'%!sort | uniq' +wq file.txt

March 22, 2012bashoneliners

Explanation

We open a file with vi and run two vi commands (specified with +):

  1. %!sort | uniq
    • % = range definition, it means all the lines in the current buffer.
    • ! = run filter for the range specified. Filter is an external program, in this example sort | uniq
  2. wq = write buffer contents to file and exit.