Random shuffle of lines of a TXT file

Hello friends,

I have a TXT file with 300 lines in it. I need to shuffle all the lines (randomly) so that they get into different order. Can anyone pls provide easy way, if any?

I got it done by doing this below but I see it very lengthy/inefficient way.

call random function to generate from 1-300 (uniq - without repetition) and use "head -$num |tail -1" to get that line and redirect to new file. It worked but looking for better way.

TIA

If you're lucky you'll have the shuf utility, which will do exactly that. You'll find it in many Linux/GNU systems.

shuf < inputfile > outputfile
1 Like

Thank you Corona for a perfect quick reply! :b:

It worked great!! :slight_smile:

1 Like