How do I pick a random row of text from a file?
Asked
Active
Viewed 63 times
0
How do I pick a random row of text from a file?
head -n 1 file
will give you the first row,tail -n 1 file
will give you the last one. – Kusalananda Jan 30 '19 at 16:26n=$(wc -l <"$path"); head -$[(RANDOM<<15+RANDOM)%n] "$path"|tail -1
The distribution won't be perfectly level and it will see only the first billion lines of large textfiles. The location of the file should be in thepath
environment variable. – peterh Jan 30 '19 at 18:34