title: Parsing of text file to match string and extract value (in Golang)
body: <p>I am scratching my head around a need that seems to be potentially common but I couldn't locate any example on the web. </p>
  
  <p>I have a file like this: </p>
  
  <pre><code>  answer VNET_1_DHCP yes
    answer VNET_1_DHCP_CFG_HASH 4CF2C196E368CE83B9D1895C5E05301CDFDEBCA0  
    answer VNET_1_HOSTONLY_NETMASK 255.255.255.0
    answer VNET_1_HOSTONLY_SUBNET 192.168.224.0
    answer VNET_1_VIRTUAL_ADAPTER yes
    answer VNET_8_DHCP yes
    answer VNET_8_DHCP_CFG_HASH D326C0BC7FF6C38C57AF341F9075E576C175B250
    answer VNET_8_HOSTONLY_NETMASK 255.255.255.0
    answer VNET_8_HOSTONLY_SUBNET 172.16.102.0
    answer VNET_8_NAT yes
    answer VNET_8_VIRTUAL_ADAPTER yes
  </code></pre>
  
  <p>I need to extract the VNET number of a specific subnet (192.168.224.0). VNET numbers could vary (and the subnet could, in theory, not even exist). So I need to match if the subnet exists, and if exists extract the network number (<code>1</code> in this example). </p>
  
  <p>I found it to be SUPER easy to implement this in BASH: </p>
  
  <pre><code> if grep -q 192.168.224.0 ./networking; then
        echo "The ${VMNET_SUBNET} network already exists"
        NETWORK_NUMBER=$(grep ${VMNET_SUBNET} ./networking | cut -d'_' -f 2)
        echo NETWORK_NUMBER  
   else &lt;do something to create it.....&gt; 
  </code></pre>
  
  <p>I am trying to find the easiest way to implement this using Go. </p>
  
  <p>Thanks. </p>