title: How do you convert an array to a string in awk?
body: <p>The intent of this question is to provide a robust, flexible solution to a common problem.</p>
  
  <p>A frequent situation when processing text is the need to split the input into fields, manipulate fields and then recombine for printing. For example given this input:</p>
  
  <pre><code>$ cat file
      A      7  C       3
  </code></pre>
  
  <p>if we want to ensure every single digit was in .2f format and we want to retain the spacing before/after/between fields then we might write (using GNU awk for the 4th arg to split()):</p>
  
  <pre><code>$ cat tst.awk
  {
      split($0,flds,FS,seps)
      for (i in flds) {
          if (flds[i] ~ /[0-9]/) {
              flds[i] = sprintf("%.2f",flds[i])
          }
      }
  
      #### print the flds[] array, interleaving seps[] values:
      printf "%s", seps[0]
      for (i=1; i in flds; i++) {
          printf "%s%s", flds[i], seps[i]
      }
      print ""
      #####
  }
  
  $ awk -f tst.awk file
      A      7.00  C       3.00
  </code></pre>
  
  <p>That last loop where we flatten an array into a string for printing is common to many awk scripts. Sometimes the separators are stored in a different array as above, sometimes they're a specific character, sometimes they aren't needed. Also, the order we want flds[] printed in could be based on numerically ascending indices like the above, or it could be descending (e.g. to mimic the UNIX tool "rev") or it could be based on the flds[] values rather than their indices.</p>
  
  <p>So - is there an awk utility function that converts an array to a string using provided separators(s) in a specified order?</p>