Q:

Format output of array elements with variable lenght

I have this arrays, with output to a file.txt:
the first array contains all IPs in subnet (192.168.1.0, 192.168.1.1, ecc)
the second array contains an 1 if that host is up, a 0 if down, in order to obtain a matrix like this:
192.168.1.0 192.168.1.1 ...
0           1           ...   

How can I allign this elements? I want that the bit status (0 or 1) is at the center of the IP address.
Consider that the IP address may vary, depending on the machine, for example it can be
71.5.0.0
I put all my script if you need more info:
#!/bin/bash
# written by Cosimo Colaci

# Declarations
ROOT_UID=0
E_NOROOT=65
declare -a iplist

echo "Reading hosts status..."

# Must run as root.
# if [ "$UID" -ne "$ROOT_UID" ]
# then
#  echo "You need to run this script as root. Exiting..."
#  exit $E_NOROOT
# fi

# Find Gateway IP and Netmask
ip_gateway=$(route | tail -1 | awk '{print $1}')
netmask=$(route | tail -1 | awk '{print $3}')
# echo "$netmask"           FOR DEBUG

# Find subnet
OLDIFS="$IFS"
IFS=.
read -r i1 i2 i3 i4 <<< "$ip_gateway"
read -r m1 m2 m3 m4 <<< "$netmask"
subnet_ip=$(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((ii4 & m4))")
# echo "$subnet_ip"         FOR DEBUG
IFS="$OLDIFS"

# Express netmask in CIDR notation, to know how many hosts to scan
cidr_by_netmask() {
    #function returns prefix for given netmask in arg1
    bits=0
    for octet in $(echo $1| sed 's/\./ /g'); do 
         binbits=$(echo "obase=2; ibase=10; ${octet}"| bc | sed 's/0//g') 
         let bits+=${#binbits}
    done
    echo "/${bits}"
}

suffix=$(cidr_by_netmask $netmask)
# echo "$suffix"            FOR DEBUG

# First raw of matrix file: all IPs in subnet
iplist=( $(nmap -sL $subnet_ip$suffix | grep "Nmap scan report" | awk '{print $NF}') )

# echo "${iplist[@]}"           FOR DEBUG

let i=1
let j=0
while [ $j -lt ${#iplist[@]} ]
do
  raw1[$i]=${iplist[$j]}
  ((i++))
  ((j++))
done
raw1[0]="#IP/TIME"

for value in ${raw1[@]}
do
  echo -en "$value\t"
done >ip-time_matrix.txt
echo -e "\n" >>ip-time_matrix.txt

# Other raws
let j=1
let k=0

export j
export k

echo "Scanning hosts every 10s..." 
echo "Hit CTRL-C to stop and check file \"ip-time_matrix.txt\""

while true
do
  nmap -sP $subnet_ip$suffix &>temp_esame95a.txt
  raw2[0]="$(date +%T)"
  for ip in ${iplist[@]}
  do
    if grep "$ip" temp_esame95a.txt &>/dev/null
    then
      raw2[$j]="---1---"
    else
      raw2[$j]="---0---"
    fi
    ((j++))
  done
  for value in ${raw2[@]}
  do
    echo -en "$value\t"
  done >>ip-time_matrix.txt
  echo -e "\n" >>ip-time_matrix.txt
  sleep 10
  j=1
done

A:

In a comment a suggested printf "%15.15s %s" "${ip}" ${bitstatus}. I should have added a \n, printf "%15.15s %s\n" "${ip}" ${bitstatus}.
OP reacted, that it solved his problem.

