<p>This is my second HPR episode and the first in what could be a series about shell scripts I have written. This episode goes through a short script which randomly generates first and last names for a ten man aircrew to use with the Avalon Hill game B-17 Queen of the Skies.</p>
<p>You can see the basic script in action here:<br />
<a href="https://www.sodface.com/misc/qots-crew-gen" class="uri">https://www.sodface.com/misc/qots-crew-gen</a></p>
<p>and a more complicated version here, though based on the same underlying methodolgy:<br />
<a href="https://www.sodface.com/misc/qots-crew-gen2" class="uri">https://www.sodface.com/misc/qots-crew-gen2</a></p>
<p>Here’s the script:</p>
<pre><code>#!/bin/sh

first_names=&#39;./firstnames.txt&#39;
last_names=&#39;./surnames.txt&#39;
crew_positions=&#39;./positions.txt&#39;
crew_ranks=&#39;./ranks.txt&#39;

len_first_names=$(wc -l &lt; ${first_names})
len_last_names=$(wc -l &lt; ${last_names})

num_pairs=$(printf &quot;10 ${len_first_names} ${len_last_names}&quot; | \
    awk &#39;BEGIN { srand() }
    { for (i=1; i&lt;=$1; i++) {
        for(f = 2; f &lt;= NF; f++) {
        num=int(rand() * $f + 1); printf num&quot;,&quot; } printf &quot;\n&quot;
    }
    }&#39;)

i=1

for crew_member in ${num_pairs}
do
  line_num=$(printf &quot;${crew_member}&quot; | cut -d&#39;,&#39; -f1)
  first_name=$(sed -n ${line_num}p ${first_names})

  line_num=$(printf &quot;${crew_member}&quot; | cut -d&#39;,&#39; -f2)
  last_name=$(sed -n ${line_num}p ${last_names})

  crew_position=$(sed -n ${i}p ${crew_positions})
  crew_rank=$(sed -n ${i}p ${crew_ranks})

  #
  # Use the variables above to generate HTML.
  # Omitted here to simplify this example.
  #

  i=$((( ${i} +1 )))
done</code></pre>
