Questions tagged [shuf]
15 questions
3
votes
4 answers
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 this task?
I have around 50k txt files in a folder…
Akhil
- 1,220
- 2
- 16
- 31
3
votes
1 answer
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
Tiger
- 347
- 2
- 4
- 12
3
votes
1 answer
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 from here and here, so basically I am using this…
Mostafa Hussein
- 263
- 2
- 5
- 11
2
votes
2 answers
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 alphanumeric string on a new line in front of the shell…
LoopedLine
- 23
- 4
2
votes
0 answers
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 strings, sometimes numbers.
a sufficiently long random…
Tim
- 237
- 2
- 8
2
votes
2 answers
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/html_node/Random-sources.html, uses an openssl-based…
flow2k
- 561
- 1
- 8
- 19
2
votes
2 answers
Randomly select a line in every block of N lines
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 random selection a line from every four lines,…
mtherk16
- 21
- 1
0
votes
1 answer
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 manageable using find + shuffle.
I then want to find all…
Martin Pedersen
- 3
- 2
0
votes
5 answers
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
What is the first line of MOBY DICK?
(X) Call me…
Brian Fitzpatrick
- 2,755
- 3
- 23
- 43
0
votes
2 answers
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" | head -c200
for N in {1..10000}; do bash extraction_200pb.sh; done >…
GSQ
- 37
- 5
0
votes
1 answer
How to replace Shuf with rand (from C++) with a seed of time in order to make my script more random
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 tail -c+"$r" | head -c200
Do anyone knows if it is possible to change…
GSQ
- 37
- 5
0
votes
1 answer
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 file is nearly 94 GB, so we can't use shuf.Then I have…
Uday
- 101
- 1
0
votes
2 answers
Piping Output of Shuf Command
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.
There is a CLITool program I found on GitHub that…
Joey29
- 9
- 1
0
votes
0 answers
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 numbers where no files named after the numbers exist, pipe…
Tim
- 98,580
- 191
- 570
- 977
0
votes
1 answer
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.