Questions tagged [shuf]
The shuf tag has no summary.
15 questions
0 votes
1 answer
1k views
Selecting n random files from one directory and copying them to another folder + other files with same same, but different filetype
I have two directories, lets call them X and Y Within them I have 100k+ files, .jpg files in X and .txt files in Y I want to randomly select N files from X and copy to folder Z This should be ...
4 votes
2 answers
5k views
How can I add a new line after the output of a command?
I'm working in Bash using this nested shuf command to get an alphanumeric string of variable length: shuf -erz -n $(shuf -e -n 1 {0..5}) {A..Z} {a..z} {0..9} Current output: This outputs the ...
0 votes
5 answers
238 views
Can a shell script find all groups of consecutive lines matching the same regex and shuffle them?
I'm writing quizzes for my students in a markdown language. One of the quizzes might look like this: % QUESTION Who played drums for The Beatles? (X) Ringo ( ) John ( ) Paul ( ) George % QUESTION ...
0 votes
2 answers
471 views
How to sample without replacement from a script that randomly extracts 200characters using shuf?
I have this script that extracts 200 random characters from a set: #!/usr/bin/bash n=$(stat -c "%s" newfile.txt) r=$(shuf -i1-"$((n-200+1))" -n1) < newfile.txt tail -c+"$r&...
0 votes
1 answer
371 views
How to replace Shuf with rand (from C++) with a seed of time in order to make my script more random [closed]
I have this script that extracts 200 random characters from a set: tail -n+2 file.fasta | tr -d '\n' > newfile n=$(stat -c "%s" newfile) r=$(shuf -i1-"$((n-200+1))" -n1) newfile ...
0 votes
1 answer
141 views
Write all numbers between 0 and large number (both inclusive) to a file in random order
For simulation I am trying to do, I want a text file with numbers ranging from 0 to 2^33 which is a huge number. I have used this command: seq 0 Number >> OUTPUT FILE But this is very slow. The ...
2 votes
0 answers
287 views
shuffle two parallel text files not giving same lines even if same random source
This is similar to Shuffle two parallel text files I have: two large csv files with parallel lines. (they represent 'before' and 'after' states for particular items). The fields are sometimes ...
4 votes
4 answers
16k views
How to pick a random file from a folder without repetition using bash?
I can select a random file using this command find ./ -type f | shuf -n 1 But it's showing the same file some times. Is it possible to stop picking duplicate files? Is there any other utility for ...
0 votes
2 answers
655 views
Piping Output of Shuf Command [duplicate]
Fairly new to Linux. I have a nixie clock that runs off of a Raspberry Pi. I would like to send a random sequence of six digits to it every so often to help prolong the life of the Nixie tubes. ...
3 votes
1 answer
561 views
What does shuf -e means in bash
I have string save as test="test1 test2 test3 test4 test5 test6" and echo $(shuf -e $test) it gives me the same output as $test, why? I expect the different order of the original string
2 votes
2 answers
2k views
Does the size of the random_source file matter?
Some GNU coreutils utilities like sort and shuf use a file as what effectively serves a seed. Does the size of the file matter? The recommended way, https://www.gnu.org/software/coreutils/manual/...
0 votes
0 answers
198 views
Is this segment fault raised when running `shuf`?
I have a script, where there is a line: eval for i in \{"$1".."$2"\}\; do [ ! -e "$3"/\$i.\* ] \&\& echo \"\$i\" \; done \| shuf \| mycommand "$3" which means: first create a sequence of ...
3 votes
1 answer
3k views
Moving random files using shuf and mv - Argument list too long
I have a directory containing nearly 250K files, which are lots of files, and I want to move x random files to another directory. I searched and I got the solution of using the shuf and mv commands ...
0 votes
1 answer
972 views
How to select random sample of n lines from each file in a directory
I have a directory with many files. From each of these files I want a random sample and copy to a new directory with file names same as from which random sample was drawn.
2 votes
2 answers
493 views
Randomly select a line in every block of N lines [duplicate]
I'd like to randomly select a line after a given number of lines. For example here's my input: 8 blue 8 red 8 yellow 8 orange 3 pink 3 white 3 cyan 3 purple 1 magenta 1 black 1 green 1 brown and with ...