I'm new to Linux and putting some scripting skills to the test with a small loop that uses grep to parse email fields from whois record look-ups. It searches for fields that often contain registrant email addresses, then strips everything preceding the '@', leaving only the registrant domain. (Not much fun, in general, because whois records are notoriously inconsistent across regions)
I would like my final output to print the IP and its subsequent email addresses on the same row.
Here's my script in its current form:
while read ip
do
echo "$ip"
whois $ip | grep -i orgtechemail | cut -d@ -f 2 | cut -d"'" -f 1 | uniq
whois $ip | grep -i orgabuseemail | cut -d@ -f 2 | cut -d"'" -f 1 | uniq
whois $ip | grep -i e-mail | cut -d@ -f 2 | cut -d"'" -f 1 | uniq
whois $ip | grep -i notify | cut -d@ -f 2 | cut -d"'" -f 1 | uniq
whois $ip | grep -i abuse-mailbox | cut -d@ -f 2 | cut -d"'" -f 1 | uniq
whois $ip | grep -i 'abuse contact' | cut -f 9- -d' ' | uniq
done < $1
My current output looks something like this:
204.154.186.2
bcbsks.com
bcbsks.com
72.165.233.67
centurylink.com
centurylinkservices.net
But I would prefer that with each email address that is found, it prints to the same line as the IP address. Like this:
204.154.186.2 bcbsks.com bcbsks.com
72.165.233.67 centurylink.com centurylinkservices.net
I found a short awk command that gets me part of the way there, but does not fully achieve what I'm looking for:
awk '{ORS=NR % 2? " ": "\n"; print}'
Thank you!