← retour aux snippets

shuf: échantillonner ou mélanger des lignes

Prendre un échantillon aléatoire reproductible ou mélanger un fichier.

bash process #shuf#random#sample

objectif

Tester aléatoirement, splitter datasets, ou générer des ordres aléatoires.

code minimal

# échantillon de 100 lignes
shuf -n 100 data.txt > sample.txt

utilisation

# seed fixe pour reproductibilité
shuf --random-source=<(yes 42 | tr -d '\n') -n 10 list.txt

variante(s) utile(s)

# mélanger un range
shuf -i 1-10

notes

  • --random-source permet un seed custom.
  • combinez avec split pour cross-validation.