Content
2 Answers Active Oldest Votes Use shuf with the -n option as shown below, to get N random lines: 541 shuf -n N input output share improve this answer follow edited Jun 16 ’16 at 20:48 DomainsFeatured 1,234 0 1 0 18 29 answered Feb 25 ’13 at 11:03 dogbane 226k 69 351 388 35 This should be the accepted answer. Wow, shuf is sooo fast. – picking 10000 random lines from a textile with 40000 lines is instant. Trying to use ‘sort -R’ took so long I just CTRL-C it – carpii Jul 3 ’15 at 20:10 2 If you just need a random set of lines, not in a random order, then shuf is very inefficient (for big file): better is to do reservoir sampling, as in this answer. – petrelharp Sep 6 ’15 at 23:24 4 neither shuf nor sort -R are available for mac OSX. any suggestions? – Tom Smith Oct 6 ’15 at 10:06 33 TomSmith On Mac OSX, if you are using Homebrew, you can get shuf or GNU sort by installing coreutils . More info here: apple.stackexchange.comquestions142860install-shuf-on-os-x – nofinator Oct 8 ’15 at 13:11 7 shuf is fantastic. I tried in on a 78 Billion line text file and it did the job in less than 1 minute. – Ash Jan 19 ’16 at 812 7 shuf is fantastic. I tried in on a 78 Billion line text file and it did the job in less than 1 minute. – Ash Jan 19 ’16 at 8:13 78 Billion line text file The WHAT