Inicio·Comandos de terminal

shuf

Procesado de texto

Uso

shuf [file]

Devuelve las líneas en orden aleatorio; es de GNU coreutils y no existe en macOS, donde el sustituto sort -R agrupa las líneas iguales.

Opciones habituales

OpciónSignificado
-nPrint only N lines
-eTreat the arguments themselves as the lines
-iDraw from a number range, as in -i 1-100
-rAllow the same line to come out more than once
-oWrite to a file instead of standard output
--random-sourceUse a fixed source so the shuffle can be repeated

Ejemplos

shuf -n 1 names.txt

Picks one line at random.

shuf -i 1-49 -n 6

Six different numbers between 1 and 49.

sort -R names.txt

The nearest thing on a machine without shuf.

Están hechos para encadenarse con tuberías. Tres comandos unidos suelen ser más cortos que uno que lo haga todo.

Cómo leerlo

  • Los corchetes [ ] marcan una parte que puedes omitir.
  • Los puntos suspensivos … indican que puedes poner varios.
  • Las opciones distinguen mayúsculas: en algunos comandos -r y -R no hacen lo mismo.

Preguntas

Q. ¿Qué hace shuf?

Devuelve las líneas en orden aleatorio; es de GNU coreutils y no existe en macOS, donde el sustituto sort -R agrupa las líneas iguales.

Q. ¿Cómo se escribe?

shuf [file] — los corchetes marcan lo que puedes omitir.

Q. ¿Cuántas opciones vale la pena saber?

Aquí van 6; la lista completa está en man shuf. Este comando está en Procesado de texto.

Comandos relacionados

página man: man shuf