I have a file called “demo” that has names in our DNS.
I’m trying to loop through each line and replace the “names” with “names and ip address” (as a way of verifying dns queries)
So far I have this but no luck on sed or awk command. Help appreciated.
Thanks.
demo
1 10.1.22.117 qa/testing 2 172.16.1.5 dc/vpn 3 10.102.99.2 devtest/testing
“diggs” has an alias that yields one line output.
desired output
1 10.1.22.117==qa==qa qa/testing 2 172.16.1.5==dc==dc dc/vpn 3 10.102.99.2==devtest==devtest devtest/testing
process.sh
for i in $(awk -F " " '{print $2}' demo) do bothR="$i==$(diggs $i)" echo "$i==$bothR" echo "#######" #what sed? #sed -i "s/$i/$bothR/" demo #sed '0,/"$i"/s//"$bothR"/' demo done
Advertisement
Answer
Your question is very unclear as to what you’re trying to do, but is this what you’re thinking? No need for getting sed
or awk
involved.
#!/bin/bash while read -r line; do echo $line $(dig +short $line|head -1) >> output.txt done < ifile.txt