#!/bin/bash index=0 set -x # The new_hosts.txt file has lines in the format: # hostname x.x.x.x y.y.y.y # being both ips # The purpose is to read the file and store the values in an array # for several different purposes, but it's not working cat new_hosts.txt |cut -d\ -f1- | while read _host _ipold _ipnew; do ((index++)) echo "c=$index, ip_new=$_ipnew, server=$_host, ip old=$_ipold" host[${index}]=$_host ipnew[$index]=$_ipnew ipold[$index]=$_ipold done # Why $index=0? echo "RESUMEN FINAL ($index)" for ((i=1;$i<40;i++)); do echo "servidor $i: ${host[$i]}, ip antigua: ${ipold[$i]}, ip nueva: ${ipnew[$i]}" done