Aqui está uma maneira:
#!/bin/bash
filename="$1"
port="$2"
echo "STARTING NMAP"
## Read the file in batches of 100 lines
for((i=100;i<=$(wc -l < "$filename");i+=100)); do
head -n "$i" "$filename" | tail -n 100 |
while IFS= read -r line
do
## Launch the command in the background
nmap --host-timeout 15s -n $line -p $2 -oN output.txt |
grep "Discovered open port" | awk {'print $6'} |
awk -F/ {'print $1'} >> total.txt &
done
## Wait for this batch to finish before moving to the next one
## so you don't spam your CPU
wait
done