Later I realized that the fourth field has only one digit, which should have
been padded to four characters, so the script skips over that field, leading
to the unexpected entries in field eight.
Indeed. You can change the regular expression so that it catches the
character ":" and what precedes it down to the previous ":" (excluded):
$ echo $ipv6_address | sed s/'[^:]*:'/$(openssl rand -hex 2):/$(shuf -i 4-7
-n 1)
What I'm actually trying to do is to replace all of the last six fields of
the initiating IPv6 address with new four-digit hex numbers, run the script
65,536 times (...)
$ prefix=0123:4567; od -A n -N 786432 -xw12 /dev/urandom | tr ' ' : | sed
s/^/$prefix/
One call of 'od' to read 786,432 bytes from /dev/urandom should be orders of
magnitude faster than 393,216 calls of 'openssl' to generate 2 bytes each
time. I let you read 'info od' if you want to understand the options I use.