This:
echo " " | tr ' ' '\n' | sed "s|.*|$RANDOM|"
Or this:
echo " " | tr ' ' '\n' | sed "s|.*|$(echo $RANDOM)|"
Will print a list of 5 numbers (space is replaced by newline, sed replaces each line with $RANDOM), and those 5 numbers will all be the same:
$ echo " " | tr ' ' '\n' | sed "s|.*|$(echo $RANDOM)|"
21590
21590
21590
21590
21590
This is because the replace of $RANDOM to a random value happens only once.
What is the easiest and shortest way, preferably by only using sed, to actually print a different random number for each line. i.e. to provide some "secondary input stream" which differs for each line that sed handles?
I could do it with xargs, but I wonder if there is a way to do it with sed only.
Aucun commentaire:
Enregistrer un commentaire