title: Matching against regexes with bash, output is in the wrong ordering
body: <p>I have text file that need to be processed so it will return desired output.</p>
  
  <pre><code>hostname ABC1234567
  NAME: "Chassis", DESCR: "Nexus5020 Chassis"
  PID: N5K-C5020P-BF     , VID: V04 , SN: SSI13390FZT
  
  NAME: "Module 1", DESCR: "40x10GE/Supervisor"
  PID: N5K-C5020P-BF     , VID: V04 , SN: JAF1344BHNK
  
  NAME: "Module 2", DESCR: "6x10GE Ethernet Module"
  PID: N5K-M1600         , VID: V01 , SN: JAB1228018M
  
  NAME: "Module 3", DESCR: "8x1/2/4G FC Module"
  PID: N5K-M1008         , VID: V01 , SN: JAB1231020C
  </code></pre>
  
  <p>I've tried using regex to pass the value to $host variable but it's failed based on the output.</p>
  
  <pre><code>#!/bin/bash
  
  re_descr='DESCR: "([^"]+)"'
  re_sn='SN: ([^[:space:]]+)'
  re_host='hostname ([^"]+)'
  
  while read -r; do
          if [[ $REPLY =~ $re_descr ]]; then
                  descr=${BASH_REMATCH[1]}
                  continue
          fi
          if [[ $REPLY =~ $re_sn ]]; then
                  sn=${BASH_REMATCH[1]}
          fi
          if [[ $REPLY =~ $re_host ]]; then
                  host=${BASH_REMATCH[1]}
          fi
          if [[ $descr &amp;&amp; $sn ]]; then
                  printf '%s\t%s\n' "$host"-"$descr","$sn"
                  unset -v host descr sn
          fi
  done &lt; &lt;(cat file.txt)
  </code></pre>
  
  <p>Right now it will print </p>
  
  <pre><code>-Nexus5020 Chassis,SSI13390FZT
  -40x10GE/Supervisor,JAF1344BHNK
  -6x10GE Ethernet Module,JAB1228018M
  -8x1/2/4G FC Module,JAB1231020C
  </code></pre>
  
  <p>How do I get it work so it will print in this format</p>
  
  <pre><code>ABC1234567-Nexus5020 Chassis,SSI13390FZT
  ABC1234567-40x10GE/Supervisor,JAF1344BHNK
  ABC1234567-6x10GE Ethernet Module,JAB1228018M
  ABC1234567-8x1/2/4G FC Module,JAB1231020C
  </code></pre>