Gerd-Christian Michalke wrote:

Bonjour,

une petite question de script bash/sed/awk

Admettons que je veuille remplacer une chaîne de caractère par un nombre aléatoire et cette chaîne. J'ai essayé

cat fichier | sed -e "s/.*\(CHAINE\).*/${RANDOM}-\1/g"

Fort logiquement, sed va appeler une fois la variable RANDOM, ce qui fait que j'obtiendrai

nnnnnnnnn-CHAINE
nnnnnnnnn-CHAINE
nnnnnnnnn-CHAINE

et ainsi de suite. Ce n'est pas ce que je veux: pour bien faire, il faudrait qu'un nouveau nombre soit généré à chaque fois que sed trouve une occurrence de la chaîne. Il y a peut-être moyen de faire qqc avec awk, mais je ne connais pas assez ;-(

Toute idée est la bienvenue !

Merci à l'avance,
Gerd

_______________________________________________________
Linux Mailing List - http://www.unixtech.be
Subscribe/Unsubscribe: http://www.unixtech.be/mailman/listinfo/linux
Archives: http://www.mail-archive.com/[EMAIL PROTECTED]
IRC: chat.unixtech.be:6667 - #unixtech




Il y a /dev/random : j'y pompe par ex 10 bytes :

dd if=/dev/random bs=10 count=1 | od -bc

(juste essayé, jamais utilisé)

   Alain

--
------------------------------------------------------------
Dr Alain EMPAIN <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Bioinformatics, Molecular Genetics, Fac. Med. Vet., University of Liège, Belgium
Bd de Colonster, B43 B-4000 Liège (Sart-Tilman)
WORK: +32 4 366 3821 FAX: +32 4 366 4122
HOME: rue des Martyrs,7 B- 4550 Nandrin +32 85 51 23 41 GSM: +32 497 70 17 64
--------------------------------------------------------------------------------
"I worry about my child and the Internet all the time, even though she's
too young to have logged on yet. Here's what I worry about. I worry that
10 or 15 years from now, she will come to me and say 'Daddy, where were
you when they took freedom of the press away from the Internet?'" --Mike Godwin, Electronic Frontier Foundation --------------------------------------------------------------------------------


_______________________________________________________
Linux Mailing List - http://www.unixtech.be
Subscribe/Unsubscribe: http://www.unixtech.be/mailman/listinfo/linux
Archives: http://www.mail-archive.com/[EMAIL PROTECTED]
IRC: chat.unixtech.be:6667 - #unixtech

Répondre à