Diff 3 files, but diff only their 2nd column

Guys i have 3 files,
but i want to compare and diff only the 2nd column

path=`/home/whois/doms`
for i in `cat domain.tx`
do
whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant
whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin
whois $i| sed -n '/Registry Tech ID:/,/Tech Email:/p' > $path/$i.tech
done
File1.
Registry Registrant ID:
Registrant Name: Dns Admin
Registrant Organization: Google Inc.
Registrant Street: Please contact contact-admin@google.com, 1600 Amphitheatre Parkway
Registrant City: Mountain View
Registrant State/Province: CA
Registrant Postal Code: 94043
Registrant Country: US
Registrant Phone: +1.6502530000
Registrant Phone Ext:
Registrant Fax: +1.6506188571
Registrant Fax Ext:
Registrant Email: dns-admin@google.com



File2
Registry Admin ID:
Admin Name: DNS Admin
Admin Organization: Google Inc.
Admin Street: 1600 Amphitheatre Parkway
Admin City: Mountain View
Admin State/Province: CA
Admin Postal Code: 94043
Admin Country: US
Admin Phone: +1.6506234000
Admin Phone Ext:
Admin Fax: +1.6506188571
Admin Fax Ext:
Admin Email: dns-admin@google.com


File 3
Registry Tech ID:
Tech Name: DNS Admin
Tech Organization: Google Inc.
Tech Street: 2400 E. Bayshore Pkwy
Tech City: Mountain View
Tech State/Province: CA
Tech Postal Code: 94043
Tech Country: US
Tech Phone: +1.6503300100
Tech Phone Ext:
Tech Fax: +1.6506181499
Tech Fax Ext:
Tech Email: dns-admin@google.com

im hoping it will print the line the difference. if all is the same. jsut print all the data in file2

As much as I'd like to help, I can't, same as I couldn't with your last, almost identical request. How should lines be compared? Based on line No.? On item (city? phone?)? What should the output look like? What if file2's entry is identical to file1's but different to file3's?
Please be way more specific!
What have you tried so far?

---------- Post updated at 19:39 ---------- Previous update was at 19:23 ----------

Not sure if this will meet your desired result:

awk     '               {n=split ($1, T, " "); sub (T[1] " ", "", $1)}
         FNR==NR        {C[$1]=$0; next}
         $1 in C        {X=C[$1]; m=split (X, TMP); if (TMP[m] != $2) C[$1]= X ":" $2}
         END            {for (c in C) print C[c]}
        ' FS=":" OFS=":" file2 file1 file3
Email: dns-admin@google.com
Street: 1600 Amphitheatre Parkway: Please contact contact-admin@google.com, 1600 Amphitheatre Parkway: 2400 E. Bayshore Pkwy
Admin ID:
Postal Code: 94043
City: Mountain View
Country: US
Name: DNS Admin: Dns Admin: DNS Admin
State/Province: CA
Organization: Google Inc.
Fax: +1.6506188571: +1.6506181499
Fax Ext:
Phone: +1.6506234000: +1.6502530000: +1.6503300100
Phone Ext:

But: this is based on some assumptions and it is not too robust...

1 Like

Thanks Man,
but not working...

Desired Output

below are data that is not the same from google.com domain
Registry Registrant ID:
Registrant Phone: +1.6502530000

Registry Admin ID:
Admin Phone: +1.6506234000



Registry Tech ID:
Tech Phone: +1.6503300100


Just guessing at context, the OP also needs to know that whois returned data varies... (quite a bit). The record data is not uniform, there many different "valid" formats.

(something to keep in mind)

i know this is really hard..

im pretty sure harder than google hehehe

this script should be intelliegent enough to know the difference between the fields, except for the first column of course

It is hard. While this isn't a direct answer... I've posted my super whois.sh at:

http://endlessnow.com/ten/Source/whois-sh.txt

It at least tries to understand certain elements of the various formats returned by whois.

But it's focused at the more "core" common types. Some of the detail items you are wanting are really all over the place format wise and not well defined (if defined at all).

If it helps... great.... but maybe not for the content you are wanting...

whois is a poor database....

when i run your script this is the output. which what i dont want

$ sh u google.com
google.com
$ sh u google
google                                                          128.177.174.32 - 128.177.174.47 128.177.174.32  128.177.174.47  128.177.174.32/28

this is the desired.



[root@logserver doms]#    whois page.com| sed -n '/Registry Registrant ID:/,/Tech Email:/p'| sed 's/Registry Tech ID:/\n\n&/'|sed 's/Registry Admin ID:/\n\n&/'


Registry Registrant ID:
Registrant Name: page Dom-Admin
Registrant Organization: page.com LLC
Registrant Street: PO Box 192307
Registrant City: Dallas



Registry Admin ID:
Admin Name: page Dom-Admin
Admin Organization: page.com LLC
Admin Street: PO Box 11111111
Admin City:  CEBU


Registry Tech ID:
Tech Name: page Dom-Admin
Tech Organization: page.com LLC
Tech Street: PO Box 2222222
Tech City: Dallas




Desired Output:
======================================================================================
For Domain page.com, below are mismatch data,  print
Registry Registrant ID:

Registry Registrant ID:
Registrant Name: page Dom-Admin
Registrant Organization: page.com LLC
Registrant Street: PO Box 192307
Registrant City: Dallas

Mismatch Data Registry Registrant ID:
Registry Admin ID:
Admin Street: PO Box 11111111
Admin City:  CEBU

Mismatch Data from Registry Registrant ID:
Registry Tech ID:
Tech Street: PO Box 2222222
===================================================================================








Example no 2. IF NO MISMATCH

Desired Output
[root@logserver doms]#    whois page.com| sed -n '/Registry Registrant ID:/,/Tech Email:/p'| sed 's/Registry Tech ID:/\n\n&/'|sed 's/Registry Admin ID:/\n\n&/'

=========================================================================
No mismatch Data
Registry Registrant ID:
Registrant Name: page Dom-Admin
Registrant Organization: page.com LLC
Registrant Street: PO Box 192307
Registrant City: Dallas
===============================================================================


:slight_smile:

I was merely giving you an example. As mentioned ... well in the code, it's really for IP lookups.

(in other words, I guess is didn't help any... which I also said might be the case)

I'll let others write your code for you.... it's not that hard (you can figure it out I'm sure!) in your very specific case.

Got this.

for i in `cat d.tx`
do
a=`cat $i.registrant|awk -F: '{print $2}'|sort|sed '/^\s*$/d'`
b=`cat $i.admin|awk -F: '{print $2}'|sort|sed '/^\s*$/d'`
c=`cat $i.tech|awk -F: '{print $2}'|sort|sed '/^\s*$/d'`
diff <(echo "${a}")  <(echo "${b}")|grep ">"|sed -e 's/>//'|sed 's/^.//'  > $i.diff
#echo "$i.diff"
done

Interesting approach....
I fail to see a kitchen sink in there. Where is it?

first divide them

a=`cat $i.registrant|awk -F: '{print $2}'|sort|sed '/^\s*$/d'`
b=`cat $i.admin|awk -F: '{print $2}'|sort|sed '/^\s*$/d'`
c=`cat $i.tech|awk -F: '{print $2}'|sort|sed '/^\s*$/d'`

and get the diff

---------- Post updated at 10:20 AM ---------- Previous update was at 10:17 AM ----------

Ah i got you

  1. run a script
whois ymas.uy| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > /home//whois/doms/ymas.uy.registrant
whois ymas.uy| sed -n '/Registry Admin ID:/,/Admin Email:/p' > /home//whois/doms/ymas.uy.admin
whois ymas.uy| sed -n '/Registry Tech ID:/,/Tech Email:/p' > /home//whois/doms/ymas.uy.tech

whois ymas.uy.com| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > /home//whois/doms/ymas.uy.com.registrant
whois ymas.uy.com| sed -n '/Registry Admin ID:/,/Admin Email:/p' > /home//whois/doms/ymas.uy.com.admin
whois ymas.uy.com| sed -n '/Registry Tech ID:/,/Tech Email:/p' > /home//whois/doms/ymas.uy.com.tech



2. create trext file that contain your domains

vi d.tx


3. run the script above

this is such a pain..we have plety of domain and my boss wants me to identify where entries is mismatch.. man....in excel file..

you know sysadmins hates inventory/documentation and EXCEL FILE