title: Print all elements in an array in AWK
body: <p>I want to loop through all elements in an array in awk and print. The values are sourced from the file below:</p>
  <pre><code>Ala     A       Alanine
  Arg     R       Arginine
  Asn     N       Asparagine
  Asp     D       Aspartic acid
  Cys     C       Cysteine
  Gln     Q       Glutamine
  Glu     E       Glutamic acid
  Gly     G       Glycine
  His     H       Histidine
  Ile     I       Isoleucine
  Leu     L       Leucine
  Lys     K       Lysine
  Met     M       Methionine
  Phe     F       Phenylalanine
  Pro     P       Proline
  Pyl     O       Pyrrolysine
  Ser     S       Serine
  Sec     U       Selenocysteine
  Thr     T       Threonine
  Trp     W       Tryptophan
  Tyr     Y       Tyrosine
  Val     V       Valine
  Asx     B       Aspartic acid or Asparagine
  Glx     Z       Glutamic acid or Glutamine
  Xaa     X       Any amino acid
  Xle     J       Leucine or Isoleucine
  TERM    TERM    termination codon
  </code></pre>
  <p>I have tried this:</p>
  <pre><code>awk 'BEGIN{FS=&quot;\t&quot;;OFS=&quot;\t&quot;}{if (FNR==NR) {codes[$1]=$2;} else{next}}END{for (key in codes);{print key,codes[key],length(codes)}}' $input1 $input2
  </code></pre>
  <p>And the output is always <code>Cys   C   27</code> and when I replace <code>codes[$1]=$2</code> for <code>codes[$2]=$1</code> I get <code>M   Met 27</code>.</p>
  <p>How can I make my code print out all the values sequentially? I don't understand why my code selectively prints out just one element when I can tell the array length is 27 as expected. (To keep my code minimal I have excluded code within <code>else{next}</code> - Otherwise I just want to print all elements from array <code>codes</code> while retaining the <code>else{***}</code> command)</p>
  <p>According to <a href="https://unix.stackexchange.com/questions/183279/how-to-view-all-the-content-in-an-awk-array">How to view all the content in an awk array?</a>, The syntax above should work. I tried it here <code>echo -e &quot;1 2\n3 4\n5 6&quot; | awk '{my_dict[$1] = $2};END {for(key in my_dict) print key &quot; : &quot; my_dict[key],&quot;: &quot;length(my_dict)}'</code> and that worked well.</p>