title: print output to 2 seperate column in shell script
body: <p>I'm developing a shell script that is used to comparing performance of IPv4 and IPv6, I would like to print out the values in format:</p>
  
  <pre><code>line_number, IPv4_average_speed    IPv6_average_speed
  </code></pre>
  
  <p>This is the part of the code that is the main of my script:</p>
  
  <pre><code>for i in $(head -100 "${1}" | cut -d ',' -f2)
          do
              #status="alive";
  
              ping -c3 "${i}" &gt; /dev/null
              if [ $? -eq 0 ]
              then
                  status_v4="alive";
              else
                  status_v4="dead";
                  echo "Cannot ping the host "${i}"";
              fi
  
              ping6 -c3 "${i}" &gt; /dev/null
              if [ $? -eq 0 ]
              then
                  status_v6="alive";
              else
                  status_v6="dead";
              fi
  
              if [ "$status_v4" == "alive" ] &amp;&amp; [ "$status_v6" == "alive" ]
              then
                  ((line_number++))
                  ping -c3 "${i}" | tail -1 | awk '{print $4}' | cut -d '/' -f 2 | echo "$line_number,$(sed 's/$/ ms/')";     
                  ping6 -c3 "${i}" | tail -1 | awk '{print $4}' | cut -d '/' -f 2 | echo "$line_number,$(sed 's/$/ ms/')";    
              fi                      
          done        
  </code></pre>
  
  <p>I'm just able to print output like this, for example:</p>
  
  <pre><code>1, 6.542 
  1, 5.345 
  </code></pre>
  
  <p>But what I want is:</p>
  
  <pre><code>1, 6.542 5.345
  </code></pre>
  
  <p>I have tried to save the output of each <code>ping</code> into a variable, then use <code>awk</code>, but actually I messed up the code.</p>
  
  <p>I changed the part of the code inside the last <code>if</code> statement to be like this:</p>
  
  <pre><code>ipv4=$(ping -c3 "${i}" | tail -1 | awk '{print $4}' | cut -d '/' -f 2)
  ipv6=$(ping6 -c3 "${i}" | tail -1 | awk '{print $4}' | cut -d '/' -f 2) 
  awk '{print "$line_number $ipv4 $ipv6" $1 $2 $3}'
  </code></pre>
  
  <p>And it print out nothing on screen. Can someone help me with this?</p>