[text] 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 2048 answered Feb 25 13 at 1103 DomainsFeatured dogbane 2N 1234 o1 018 029 226k 69 351 388 This should be the accepted answer. Wow shuf is sooo fast. picking 10000 random lines from a textfile with 40000 lines is instant. Trying to use sort R took so long just CTRLC it carpii Jul 3 15 at 2010 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 2324 4 neither shuf nor sort R are available for mac OSX. any suggestions Tom Smith Oct 6 15 at 1006 TomSmith On Mac OSX if you are using Homebrew you can get shuf or GNU sort by installing coreutils . More info here apple.stackexchange.comquestions142860installshufonosx nofinator Oct815at 1311 7 shufis fantastic. tried in on a 78 Billion line text file and it did the job in less than 1 minute. Ash Jan 19 6 at 813 7 shufis fantastic. tried in on a 78 Billion line text file and it did the job in less than 1 minute. Ash Jan 19 16 at 813 78 Billion line text file