text: user2477: I found here this awk script: 
  BEGIN {
    headertype="";
    }
  {
    if($0 ~ "^@") {
      countread++;
      headertype="@";
    }
    else if($0 ~ "^+") {
      headertype="+";
    }
    else if(headertype="@") { # This is a nuc sequence
      len=length($0);
      if (len>4) {
        readlength[len]++;
      }
    }
  }
  END {
    for (i in readlength){
      countstored+=readlength[i];
      lensum+=readlength[i]*i;
      print i, readlength[i];
    }
    print "reads read = "countread > "/dev/stderr";
    print "reads stored = "countstored > "/dev/stderr";
    print "read average length = "lensum/countstored > "/dev/stderr";
  }
  
  and I just wonder if it is possible to shorten it with bioawk?
  
  user37: This script is wrong because a quality string may start with @. With bioawk, it can be simplified to:
  bioawk -c fastx '{ readlength[length($seq)]++; countread++ } END{...}'
  
  The END{} block is the same as your original version.
  EDIT: forgot -c fastx is the original answer. Thank @MattBashton for pointing this out.
  
  user964: This can also be done with regular awk.
  awk '{if(NR%4==2) {count++; bases += length} } END{print bases/count}' <fastq_file>
  
  The NR%4==2 count the second line out of every block of 4.  length is a built-in that defaults to the length of the line, same as length($0).  In this case you can inject you custom printing to the END{} block but countread and countstored will always be the same since the averaging is done on the fly.
  
original_text: 2477: <p>I found <a href="http://cagt.bu.edu/w/images/8/81/Avg_read_len_fastq.awk" rel="nofollow noreferrer">here</a> this awk script: </p>
  
  <pre><code>BEGIN {
    headertype="";
    }
  {
    if($0 ~ "^@") {
      countread++;
      headertype="@";
    }
    else if($0 ~ "^+") {
      headertype="+";
    }
    else if(headertype="@") { # This is a nuc sequence
      len=length($0);
      if (len&gt;4) {
        readlength[len]++;
      }
    }
  }
  END {
    for (i in readlength){
      countstored+=readlength[i];
      lensum+=readlength[i]*i;
      print i, readlength[i];
    }
    print "reads read = "countread &gt; "/dev/stderr";
    print "reads stored = "countstored &gt; "/dev/stderr";
    print "read average length = "lensum/countstored &gt; "/dev/stderr";
  }
  </code></pre>
  
  <p>and I just wonder if it is possible to shorten it with bioawk?</p>
   37: <p>This script is wrong because a quality string may start with <code>@</code>. With bioawk, it can be simplified to:</p>
  
  <pre><code>bioawk -c fastx '{ readlength[length($seq)]++; countread++ } END{...}'
  </code></pre>
  
  <p>The <code>END{}</code> block is the same as your original version.</p>
  
  <p>EDIT: forgot <code>-c fastx</code> is the original answer. Thank @MattBashton for pointing this out.</p>
   964: <p>This can also be done with regular awk.</p>
  
  <pre><code>awk '{if(NR%4==2) {count++; bases += length} } END{print bases/count}' &lt;fastq_file&gt;
  </code></pre>
  
  <p>The <code>NR%4==2</code> count the second line out of every block of 4.  <code>length</code> is a built-in that defaults to the length of the line, same as <code>length($0)</code>.  In this case you can inject you custom printing to the <code>END{}</code> block but <code>countread</code> and <code>countstored</code> will always be the same since the averaging is done on the fly.</p>
  