How to replace characters with random characters

[LEFT]I've got a file (numbers.txt) filled with numbers and I want to replace each one of those numbers with a new random number between 0 and 9. This is my script so far:

#!/bin/bash
rand=$(($RANDOM % 9))
sed -i s/[0-9]/$rand/g numbers.txt

The problem that I have is that it replaces each number with just one random number (for example 82197 would just become 33333). Is there any way that I can get the script to replace each number with a random number?
[/LEFT]

awk 'BEGIN{srand()}{for (i=1;i<=length;i++) printf "%d",int(10*rand()); printf "%s","\n"}' numbers.txt > numbers2.txt
1 Like
nawk 'BEGIN{OFS=FS="";srand()}{for(i=1;i<=NF;i++)sub(/[0-9]/,int(10*rand()),$i)}1' infile > outfile
1 Like