If you run the shuf command, again and again, you will get a different result each time: $ shuf random_file.txt In our case, its implementation will be as follows: $ shuf sample_file.txtĪs you can see, we have managed to randomly shuffle the lines in our sample text file. The working mechanism of the shuf command is as follows it first loads the input data into memory, references if the free memory is larger than the input data/file size before proceeding with its execution. The main function of the shuf command is to generate random permutations based on an input fed to it. Since the GNU Coreutils package hosts shuf command, it should be installed by default in your Linux operating system distribution. Shuffling Lines Using the Shuf Command in Linux The occurrence of these three lines will help us understand how different shuffling commands work. Also, as you might have noted, lines 12 to 14 are repetitive. The cat command output tells us that we are dealing with a text file with a total of 15 lines. We can use the cat command for the numbered view of this entire file: $ cat -n sample_file.txt We will need to create a sample text file with a few lines which we will be referencing while implementing and executing various to-be-discussed Linux shuffling commands.
0 Comments
Leave a Reply. |