If you run the output from your mysql-query through the following commands, it will give you the desired output. You can use this output to be evaluated, for example pipe it into a file and execute that file as a shell script.
mysql | grep -v '\$' | while read line; do echo "${line}" | sed 's#\(^[0-9]*\)[\ ]*\([0-9\.]*\)#rsync -rvp *.\1.extension root@\2:/path/of/dest#g'; done
Here are the details of the command:
mysql # Your command with output (this is of course longer than this)
grep -v '\$' # Exclude the header
while read line; do # Start a while-loop
echo "${line}" # Echo the contents of the current line that we've read to the next command
# Regular expression to filter the number and the IP and add these to the command, they are held by the variables \1 \2.
sed 's#\(^[0-9]*\)[\ ]*\([0-9\.]*\)#rsync -rvp *.\1.extension root@\2:/path/of/dest#g'
done; # Close the while loop
And the contents of the regexp explained:
(^[0-9]*\) # From the beginning (^), zero or more (*) numerical [0-9] character
[\ ]* # Zero or more (*) spaces. These are not in brackets, so they won't be matched into a variable.
([0-9\.]* # Zero or more (*) numerical characters or points [0-9\.]