Silver-0-surfer
Well-Known Member
Hi all
I have written a bash script to do this for me.
I have a table with about 150 000 usernames in it. I would like to divide them up into groups of 1000 and the assign a value depending to what group they are in for example.
the first 1000 users will be group 1, then next 1000 are group 2 and so on. This is what I have written.
<code>
echo "Enter the file name"
read users
index=0
count=0
while read line ; do
if [ $(($index%1000)) -eq 0 ]; then
let count=count+1
#a=$(($index%1000))
#echo $a
echo $count
MYARRAY[$index]="$line"
index=$(($index+1))
echo "update table set group='$count' where user='$line';" | mysql database;
else
#a=$(($index%1000))
#echo $a
#echo $count
MYARRAY[$index]="$line"
index=$(($index+1))
echo "update table set group='$count' where user='$line';" | mysql database;
fi
done < $users
</code>
Now from what I can tell it works. (I am not very skilled at this tbh) but it is taking FOREVER. its been goin since around 10am and its at around group 40 atm.
Does anyone know why its so slow?maybe I can tweak it to get better performace?
What do you guys think?
I have written a bash script to do this for me.
I have a table with about 150 000 usernames in it. I would like to divide them up into groups of 1000 and the assign a value depending to what group they are in for example.
the first 1000 users will be group 1, then next 1000 are group 2 and so on. This is what I have written.
<code>
echo "Enter the file name"
read users
index=0
count=0
while read line ; do
if [ $(($index%1000)) -eq 0 ]; then
let count=count+1
#a=$(($index%1000))
#echo $a
echo $count
MYARRAY[$index]="$line"
index=$(($index+1))
echo "update table set group='$count' where user='$line';" | mysql database;
else
#a=$(($index%1000))
#echo $a
#echo $count
MYARRAY[$index]="$line"
index=$(($index+1))
echo "update table set group='$count' where user='$line';" | mysql database;
fi
done < $users
</code>
Now from what I can tell it works. (I am not very skilled at this tbh) but it is taking FOREVER. its been goin since around 10am and its at around group 40 atm.
Does anyone know why its so slow?maybe I can tweak it to get better performace?
What do you guys think?