title: shell script to set amazon ec2 hostname from tags
body: <p>I am trying to set amazon EC2 hostname from the tag "Name"</p>
  
  <p>And found <a href="https://stackoverflow.com/a/7122649/957423">the answer</a> to extract tags from instance data.</p>
  
  <pre><code>ec2-describe-tags \
    --filter "resource-type=instance" \
    --filter "resource-id=$(ec2-metadata -i | cut -d ' ' -f2)" \
    --filter "key=Name" | cut -f5
  </code></pre>
  
  <p>the result is:</p>
  
  <pre><code>+------------+--------------+------+--------+
  | resourceId | resourceType | key  | value  |
  +------------+--------------+------+--------+
  | i-1xxxxxxx | instance     | Name | dev200 |
  +------------+--------------+------+--------+
  </code></pre>
  
  <p>I can see that I am almost there, but how do I get the value(dev200) from the result above?  Then I can use it in:</p>
  
  <pre><code>echo $HOSTNAME &gt; /etc/hostname
  </code></pre>
  
  <p>p.s. I have BASH on the instance, but I am completely lost in the <a href="http://www.tldp.org/LDP/abs/html/" rel="nofollow noreferrer">bash document</a>. can someone point me to the correct paragraph?</p>