title: Need To Generate New Random Numbers For Each Sed Substitution Used In "While Loop"
body: <p>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:</p>
  
  <pre><code>#!/bin/bash
  #
  #
  random_number()
      {
      for i in {1}; do tr -c -d 0-9 &lt; /dev/urandom | head -c 10; done
      }
  
  while read line
      do
          sed -E "s/[&lt;]FITID[&gt;][[:digit:]]+/&lt;FITID&gt;$(random_number)/g"
      done&lt;~/Desktop/FITIDTEST.QFX
  </code></pre>
  
  <p>Here's a sample of what the original FITIDTEST.QFX file looks like:</p>
  
  <pre><code>                &lt;FITID&gt;1266821191
  
                  &lt;FITID&gt;1267832241
  
                  &lt;FITID&gt;1268070393
  
                  &lt;FITID&gt;1268565193
  
                  &lt;FITID&gt;1268882385
  
                  &lt;FITID&gt;1268882384
  </code></pre>
  
  <p>And here is the output after executing the script:</p>
  
  <pre><code>                &lt;FITID&gt;4270240286
  
                  &lt;FITID&gt;4270240286
  
                  &lt;FITID&gt;4270240286
  
                  &lt;FITID&gt;4270240286
  
                  &lt;FITID&gt;4270240286
  
                  &lt;FITID&gt;4270240286
  </code></pre>
  
  <p>I need those 10 digit numbers to be different for each  field.  I thought the "while loop" would force sed to call the <strong>random_number()</strong> 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!</p>