I'm using sed to substitute a random 10 digit string of numbers for a certain field in a file, which I can successfully do. However, the same random 10 digit string of numbers are used for each substitution sed performs which is unacceptable in this case. I need a new random 10 digit string of numbers for every substitution sed performs. Here's what I have so far:
#!/bin/bash
#
#
random_number()
{
for i in {1}; do tr -c -d 0-9 < /dev/urandom | head -c 10; done
}
while read line
do
sed -E "s/[<]FITID[>][[:digit:]]+/<FITID>$(random_number)/g"
done<~/Desktop/FITIDTEST.QFX
Here's a sample of what the original FITIDTEST.QFX file looks like:
<FITID>1266821191
<FITID>1267832241
<FITID>1268070393
<FITID>1268565193
<FITID>1268882385
<FITID>1268882384
And here is the output after executing the script:
<FITID>4270240286
<FITID>4270240286
<FITID>4270240286
<FITID>4270240286
<FITID>4270240286
<FITID>4270240286
I need those 10 digit numbers to be different for each field. I thought the "while loop" would force sed to call the random_number() function each time but apparently it's called once and the value is stored and used repeatedly. Is there anyway to avoid that? Any help is greatly appreciated!