Results 1 to 5 of 5

Thread: Random line sorting

  1. #1
    Join Date
    Sep 2008
    Location
    Italy
    Beans
    96
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    Random line sorting

    I have a text file with an alphabetical list of 100+ entries. I'd like to sort it into a random order but the only tools I can find via scripts or CLI only give non-random options. Anyone have leads on how to do this?

    Thanks in advance.

  2. #2
    Join Date
    Sep 2006
    Beans
    2,914

  3. #3
    Join Date
    Sep 2008
    Beans
    551
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Random line sorting

    Code:
    sort -R file.txt > random_sorted_file.txt

  4. #4
    Join Date
    Sep 2008
    Location
    Italy
    Beans
    96
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    Re: Random line sorting

    I tried using sort -R but for it seems that that method grouped like terms together, so it was a random sort in alphabetical blocks, ie: dddd, ff ,hhh, e, rrr, aaaa, mm.

    Also, discovered the "shuf" command, which was a one-liner (shuf < input_file > output_file) and worked great.

    Ghostdog74, your script worked like a charm, and I also got a lesson in how to use awk. thanks for the responses!

  5. #5
    Join Date
    Sep 2006
    Beans
    2,914

    Re: Random line sorting

    Quote Originally Posted by AstroLlama View Post
    Also, discovered the "shuf" command, which was a one-liner (shuf < input_file > output_file) and worked great.
    yes, shuf is another command you can use. take note that it is always available in every distribution.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •