please find updated answer as i modified the BMW's answer for you please check it.
#!/bin/bash
echo "Reading data - headers - both"
if [ $# -ne 3 ]; then
echo "Usage: ./nmap <port-range> <ip-list> <d || h || b>"
exit 1
fi
join -j 2 $2 $1 > temp.txt
headers()
{
while read -r ip port
do
printf "ip: %s port:%d \n" $ip $port
OUT=$(nmap -p "$port" --script=http-headers.nse "$ip" | tac | awk -F: 'NR<=13&&/Apache/{print $2; exit}')
if [[ "$OUT" == *Apache* ]]; then
echo $ip $port >> /tmp/right.txt
else
echo $ip $port >> /tmp/wrong.txt
fi
done < temp.txt
}
case $3 in
"h") headers ;;
"d") echo data;;
"b") echo both;;
"*") echo "wrong input"
exit;;
esac