The following code makes a list of names and 'numbers' and gives each person a random age between 15 and 90.
#!/bin/sh
file=$1
n=$2
# if number is zero exit
if [ "$n" -eq "0" ]
then
exit 0
fi
echo "Generating list of $n people."
for i in `seq 1 $n`;
do
let "NUM=($RANDOM%75)+15"
echo "name$i $NUM (###)###-####" >> $file
done
echo "List generated."
With it I'm attempting to make a list of 1M names. It's slow, I expected that; it was so slow tho that I lost patience and tried 10K names. That was slow too, but it got done in a few seconds.
The reason I'm generating the names is to sort them. What surprised me is that when I sorted the list of 10K names it was instant.
How can this be?
Is there something that's making this go ungodly slow? Both the sorting and the generating are accessing files so how can the sorting be faster? Is my random number math in the list generator what's slowing it down?
Here's my sorting script.
#!/bin/sh
#first argument is list to be sorted, second is output file
tr -s '' < $1 | sort -n -k2 > $2