This is the code I wrote to resolve DNSs and output to a file. Is there a way to forgo the while
loop entirely and just write in awk
? It works perfectly but it seems very cumbersome and inefficient, takes about 10 mins for 25k lines of IPs. Will gladly elaborate on script if clarity is needed.
#!/bin/bash
while read line; do
echo -en " ${startCount} / ${endCount} IPs resolved\r"
ip=$(echo ${line} | cut -d "," -f1)
col2=$(nslookup ${ip} | fgrep "name" | sed -e 's/\t/,/g' -e 's/name = //g' -e 's/.uncc.edu.//g' | cut -d "," -f2)
if [[ ! -z ${col2} ]]; then
echo "${line}" | awk -F"," -v var="${col2}" '{print $1","var","$2","$3","$4","$5","$6}' >> ${outFile}
else
echo "${line}" | awk -F"," '{print $1",""UNRESOLVED"","$2","$3","$4","$5","$6}' >> ${outFile}
fi
((startCount++))
done < ${1}
Try this:
ref: https://www.gnu.org/software/gawk/manual/html_node/Two_002dway-I_002fO.html