My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# ----------------------------------------------------------------------------
# Desordena as linhas de um texto (ordem aleatória).
# Uso: zzshuffle [arquivo(s)]
# Ex.: zzshuffle /etc/passwd # desordena o arquivo de usuários
# cat /etc/passwd | zzshuffle # o arquivo pode vir da entrada padrão
#
# Autor: Aurelio Marinho Jargas, www.aurelio.net
# Desde: 2008-06-19
# Licença: GPL
# ----------------------------------------------------------------------------
zzshuffle ()
{
zzzz -h shuffle "$1" && return

local linha

# Arquivos via STDIN ou argumentos
zztool file_stdin "$@" |

# Um número aleatório é colocado no início de cada linha,
# depois o sort ordena numericamente, bagunçando a ordem
# original. Então os números são removidos.
while read linha
do
echo "$RANDOM $linha"
done |
sort |
cut -d ' ' -f 2-
}

Change log

r710 by aureliojargas on Mar 29, 2012   Diff
SEGURANÇA: $1 colocado entre aspas na
chamada padrão zzzz -h de todas as
funções.
Go to: 
Sign in to write a code review

Older revisions

r668 by aureliojargas on Mar 28, 2012   Diff
lint: removendo espaços inúteis.
r655 by aureliojargas on Mar 23, 2012   Diff
s/Aurélio/Aurelio/ *
r510 by aureliojargas on May 21, 2011   Diff
zzshuffle: Agora usa zztool
file_stdin. A multi_stdin é pra o
texto via argumentos, me enganei.
All revisions of this file

File info

Size: 864 bytes, 29 lines
Powered by Google Project Hosting